Code for "Do not place another order in same hour when you got a loss order already" - page 2

 
SDC:


When code is decompiled the decompiler recreates the source code in such a way that an experienced programmer can immediately recognise it as decompiled code. The rules of this forum pretty much amount to this: Decompiled code is considered stolen. As it is very difficult to prove it is not stolen the rule of thumb is, avoid altercations with the moderators by only posting questions about original source code.

You didn't understand my point 100% and I guess that's the reason why your answer doesn't help.

I didn't challenged the rules of the forum or the moderator's decision. Most issues are raised by members, not moderators.

Don't get me wrong but the rule " you're guilty because I say so and it is very difficult to prove me wrong " doesn't really make any sense, does it?

"If you deliberately obscured the variables yourself there would be little point in posting it, who is going to spend their time trying to unravel your deliberately obscured code to help you with it ?"

All I said was that if I was trying to protect my EA from others I wouldn't use " d_Spread " or any other meaningful names .

If I had a protection worth EA, would I post on the forum for help? Probably not.

Your answer would have been more interesting if you'd truly answer the original question about how one can tell if the code is or isn't stolen.

(I would ask the moderator to please post a link where we could read more about the rule that says that all decompiled code is stolen, or what are the criteria based upon which we can determine if the code is in fact stolen.)

Your answer doesn't help at all : " an experienced programmer can immediately recognize ...". Should we have the code inspected by an experienced programmer before posting ?

Or maybe if one isn't an experienced programmer, shouldn't post anything?

Or maybe we should let the moderators decide and get off of that high horse of ours every now and then and have a closer look at the real world around us.

 
Jhay82:

Hello,

Curious if anyone knows how to do this.

I mean, when my sell or buy order closed at 8:17pm with a loss, I dont want to place an order until 8:59pm or something like that.

I'd appreciate if anyone knows code for this.

My regards.



Here is an idea to stop an EA placing orders if last one was a loss for that hour.

First you need to loop trough history and find the last closed trade, the one with the highest closing time.

Here's how I see it :

//---
   if(OrdersHistoryTotal()>prevHistoryCount) // if a new order was closed
     {
      prevHistoryCount++;                                               //update history count
      for(int x=0;x<OrdersHistoryTotal();x++)
        {
         if(OrderSelect(x,SELECT_BY_POS,MODE_HISTORY)==false) // select orders from history
           {
            Print("OrderSelect from history failed error code is "+
                  GetLastError());                                      // if it fais to select, give me the error number
            return;
           }
         if(OrderCloseTime()>orderCloseTime) //if order is newer than previous
           {
            orderCloseTime=OrderCloseTime();
            orderSymbol=OrderSymbol();
            orderDirection=OrderType();
            orderProfit=OrderProfit();
            tradeMinute=TimeMinute(orderCloseTime);
           }
        }// end for

     }
//---

Then, once the loop sets all the right values, do the check for symbol and profit.

If profit < 0, set the datetime prevTime to the time when order was closed + amount of minutes from the time of closing to the end of the hour:

//---
   if(orderSymbol==Symbol() && orderProfit<0) //if last exit on loss was this symbol
     {
      prevTime=orderCloseTime+((59-tradeMinute)*60);
      }
//---

Remember, this loops and checks have to be done before the routine that opens new orders !!!

Then insert condition before Order send :

   myTrades=0;
   for(total=OrdersTotal();total>=0;total--)
     {
      if(!OrderSelect(total,SELECT_BY_POS,MODE_TRADES))
      Print("OrderSelect failed in CountMyTrades with error : "+GetLastError());
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber) continue;
      if(OrderType()==OP_SELL || OrderType()==OP_BUY)myTrades++;   
     }
  if(myTrades<1 && Time[0]>=prevTime)
     {

The count of EA's orders is made by this loop. ( you may have to rename MagicNumber to whatever name you use for it).

So if there are no trades placed by this EA and the no trading time has passed, place a new trade.

You may define the variables as static local or just global scope. For example :

void OnTick()
  {
//---
   static int orderDirection=-1;
   static int prevHistoryCount=0;
   static double orderProfit=0;
   static string orderComment;
   static string orderSymbol;

Hope it helps.

And if you have any questions, ask away.

Enjoy.

 

You need to check for symbol and magic number in the loop although I would think it easier to get OrderTicket() and re-select it.

         if(OrderCloseTime()>orderCloseTime && orderSymbol==Symbol() && orderProfit<0) //if order is newer than previous
           {
            orderCloseTime=OrderCloseTime();
            orderDirection=OrderType();
            tradeMinute=TimeMinute(OrderCloseTime());
           }
 
thanks for code have trouble putting code into.
//----------------------- USER INPUT
extern int MA_length = 10;
extern double Percent = 0.75; //for H1 charts use 0.75%,daily 2%, h4 1%,m30 0.7%
extern int TradeOnFriday =1; // >0 trades on friday
extern int MAtype=1;//0=close, 1=HL              
extern int slip = 100;//exits only
extern int Lots = 1;

extern int TakeProfit = 20;
//extern double OrderProfit = 0;
extern int Stoploss = 50;// total loss on all open positions in pips
//extern double TrailingStop = 5;
extern int PipStep = 10;//if position goes this amount of pips against you add another.
extern double IncreasementType =0;//0=just add every PipStep,  >0 =OrdersToal()^x *Pipstep
double Stopper=0;
double KeepStopLoss=0;
double KeepAverage;
double dummy;
double spread=0;
double CurrentPipStep;
int OrderWatcher=0;
//----------------------- MAIN PROGRAM LOOP
int start()
{
double PriceTarget;
double AveragePrice;
int OpeningDay;

//----------------------- CALCULATE THE NEW PIPSTEP
CurrentPipStep=PipStep;
if(IncreasementType>0)
  {
  CurrentPipStep=MathSqrt(OrdersTotal())*PipStep;
  CurrentPipStep=MathPow(OrdersTotal(),IncreasementType)*PipStep;
  } 

//----------------------- 
int Direction=0;//1=long, 11=avoid long, 2=short, 22=avoid short
 
if (Day()!=5 || TradeOnFriday >0)
{
   int cnt=0, total;
   total=OrdersTotal();
   if(total==0) OpeningDay=DayOfYear();
   OrderSelect(total-1, SELECT_BY_POS);
   double LastPrice=OrderOpenPrice();
      
   OrderSelect(total, SELECT_BY_POS, MODE_TRADES); 
   
   
//----------------------- ENTER POSITION BASED ON OPEN
OrderWatcher=0;
if(MAtype==0)
{
   if((iMA(NULL,0,MA_length,0,MODE_SMA,PRICE_OPEN,0)*(1+Percent/100))<Bid && Direction!=22 && (Bid>=(LastPrice+(CurrentPipStep*Point))||total==0)) // Go SHORT -> Only sell if >= 30 pips above previous position entry 
          {
      OrderSend(Symbol(),OP_SELL,Lots,Bid,slip,Bid+(Stoploss*Point),Bid-(TakeProfit*Point),0,0,Red);
      OrderWatcher=1;
      Direction=2;
     }   
   if((iMA(NULL,0,MA_length,0,MODE_SMA,PRICE_OPEN,0)*(1-Percent/100))>Ask && Direction!=11 && (Ask<=(LastPrice-(CurrentPipStep*Point))||total==0)) // Go LONG -> Only buy if >= 30 pips below previous position entry    

//   if((iMA(NULL,0,MA_length,0,MODE_SMA,PRICE_OPEN,0)*(1-Percent/100))>Ask &&                  (Ask<=(LastPrice-(       PipStep*Point))||total==0))     
     
     
     {
      OrderSend(Symbol(),OP_BUY,Lots,Ask,slip,Ask-(Stoploss*Point),Ask+(TakeProfit*Point),0,0,Blue);
      OrderWatcher=1;
      Direction=1;
     } 
}     
  
//----------------------- ENTER POSITION BASED ON HIGH/LOW
if(MAtype==1)
{
   if((iMA(NULL,0,MA_length,0,MODE_SMA,PRICE_HIGH,0)*(1+Percent/100))<Bid && Direction!=22 && (Bid>=(LastPrice+(CurrentPipStep*Point))||total==0)) // Go SHORT -> Only sell if >= 30 pips above previous position entry 
             {
      OrderSend(Symbol(),OP_SELL,Lots,Bid,slip,Bid+(Stoploss*Point),Bid-(TakeProfit*Point),0,0,Red);
      OrderWatcher=1;
      Direction=2;
     }   
  if((iMA(NULL,0,MA_length,0,MODE_SMA,PRICE_LOW,0)*(1-Percent/100))>Ask && Direction!=11 && (Ask<=(LastPrice-(CurrentPipStep*Point))||total==0)) // Go LONG -> Only buy if >= 30 pips below previous position entry      
//  if((iMA(NULL,0,MA_length,0,MODE_SMA,PRICE_LOW,0)*(1-Percent/100))>Ask && (Ask<=(LastPrice-(PipStep*Point))||total==0)) // Go LONG -> Only buy if >= 30 pips below previous position entry    


        {


      OrderSend(Symbol(),OP_BUY,Lots,Ask,slip,Ask-(Stoploss*Point),Ask+(TakeProfit*Point),0,0,Blue);
      OrderWatcher=1;
      Direction=1;
     } 
}                   
//----------------------- CALCULATE AVERAGE OPENING PRICE
 
   total=OrdersTotal();
   AveragePrice=0;  

 if(total>1 && OrderWatcher==1)
   {
   for(cnt=0;cnt<total;cnt++)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      AveragePrice=AveragePrice+OrderOpenPrice();
      }
   AveragePrice=AveragePrice/total;
   }
//----------------------- RECALCULATE STOPLOSS & PROFIT TARGET BASED ON AVERAGE OPENING PRICE
OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
        
    if(OrderType()==OP_BUY  && OrderWatcher==1 && total>1)// && OrderSymbol()==Symbol()) // Calculate profit/stop target for long 
      {
      PriceTarget=AveragePrice+(TakeProfit*Point);
      Stopper=AveragePrice-(((Stoploss*Point)/OrdersTotal())); 
      }
    if(OrderType()==OP_SELL && OrderWatcher==1 && total>1)// && OrderSymbol()==Symbol()) // Calculate profit/stop target for short
      {
      PriceTarget=AveragePrice-(TakeProfit*Point);
      Stopper=AveragePrice+(((Stoploss*Point)/OrdersTotal())); 
      }
//----------------------- IF NEEDED CHANGE ALL OPEN ORDERS TO THE NEWLY CALCULATED PROFIT TARGET    
if(OrderWatcher==1 && OrdersTotal()>1)// check if average has really changed
  { 
    total=OrdersTotal();  
    for(cnt=0;cnt<total;cnt++)
       {
       OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);            
       OrderModify(OrderTicket(),0,Stopper,PriceTarget,0,Yellow);// set all positions to averaged levels
       } 
  }

//----------------------- KEEP TRACK OF STOPLOSS TO AVOID RUNAWAY MARKETS
// Sometimes the market keeps trending so strongly the system never reaches it's target.
// This means huge drawdown. After stopping out it falls in the same trap over and over.
// The code below avoids this by only accepting a signal in teh opposite direction after a SL was hit.
// After that all signals are taken again. Luckily this seems to happen rarely. 
if (OrdersTotal()>0)
   {
   OrderSelect(0, SELECT_BY_POS, MODE_TRADES); 
   KeepStopLoss=OrderStopLoss();
   KeepAverage=AveragePrice;
   if(OrderType()==OP_BUY) 
     Direction=1;//long
     else Direction=2;//short
   }

if(KeepStopLoss!=0)
  {
  spread=MathAbs(KeepAverage-KeepStopLoss)/2;
  dummy=(Bid+Ask)/2;
  if (KeepStopLoss<(dummy+spread) && KeepStopLoss>(dummy-spread))
     {
     // a stoploss was hit
     if(Direction==1) Direction=11;// no more longs
     if(Direction==2) Direction=22;// no more shorts
     }
  KeepStopLoss=0;
  }
      
}
}
 
thrdel:

Don't get me wrong but the rule " you're guilty because I say so and it is very difficult to prove me wrong " doesn't really make any sense, does it?

Your answer would have been more interesting if you'd truly answer the original question about how one can tell if the code is or isn't stolen.

(I would ask the moderator to please post a link where we could read more about the rule that says that all decompiled code is stolen, or what are the criteria based upon which we can determine if the code is in fact stolen.)

Your answer doesn't help at all : " an experienced programmer can immediately recognize ...". Should we have the code inspected by an experienced programmer before posting ?

Or maybe if one isn't an experienced programmer, shouldn't post anything?

Or maybe we should let the moderators decide and get off of that high horse of ours every now and then and have a closer look at the real world around us.

1) It makes a lot more sense. If you break the rule you are guilty by the fact. If you post decompiled code your guilty of posting decompiled code.

2) Of course there is no way to tell if code is definately stolen just by looking at it. But if it is decompiled it is likely it is. No one decompiles their own code and then posts it on a forum because they dont understand it. They do that to other peoples compiled code.

3) No you dont need to get code inspected before you post it. Just go ahead and post it. If a moderator believes the code contravines a forum rule they will remove it from your post and warn you. If by some slim chance that were to happen, then so what ? Is it going to ruin your entire day or something ? It's not like the FBI is going to show up at your house with a swat team. I think your making issue out of nothing.

4) The real world around us is like this, all the time people are breaking copyrighted code protection, decompiling it and distributing it on the internet. How would you feel if you put 6 months into developing software as a business venture and then someone decompiled it and bit torrent it and posting it on forums, your 6 months work given away willy nilly all over the world. If you would not like it yourself then you should understand why others try to make it socially unacceptable.

I used to think the moderators on this forum were being a little over zealous about banning decompiled code, but when I thought it through I realised they are doing it for the right reasons.

 
SDC:

1) It makes a lot more sense. If you break the rule you are guilty by the fact. If you post decompiled code your guilty of posting decompiled code.

Not even close to answering the question " how can one tell if the code is decompiled or stolen?"

2) Of course there is no way to tell if code is definately stolen just by looking at it. But if it is decompiled it is likely it is. No one decompiles their own code and then posts it on a forum because they dont understand it. They do that to other peoples compiled code.

The question was how a person with less than expert qualifications can tell if the code is decompiled or stolen ? Your answer was blah, blah, blah.... there is no way to tell but .........it likely is. How's that supposed to help ?

3) No you don't need to get code inspected before you post it. Just go ahead and post it. If a moderator believes the code contravines a forum rule they will remove it from your post and warn you. If by some slim chance that were to happen, then so what ? Is it going to ruin your entire day or something ? It's not like the FBI is going to show up at your house with a swat team. I think your making issue out of nothing.

Buddy, I'm not making an issue, I'm asking a question and if you don't have the answer, it's OK. Glad to hear we agree on at least one thing and that is : It's the moderator's job NOT members to decide if a code is or isn't stolen !

4) The real world around us is like this, all the time people are breaking copyrighted code protection, decompiling it and distributing it on the internet. How would you feel if you put 6 months into developing software as a business venture and then someone decompiled it and bit torrent it and posting it on forums, your 6 months work given away willy nilly all over the world. If you would not like it yourself then you should understand why others try to make it socially unacceptable.

I used to think the moderators on this forum were being a little over zealous about banning decompiled code, but when I thought it through I realised they are doing it for the right reasons.

So your answer is : you can't tell for sure if the code is stolen or not, if you're not experienced you can't even tell if it's decompiled or not, so so don't buy, don't download and don't post it unless you 're sure it isn't decompiled or stolen, right? Are you serious?

If you put six months of work in an EA that's worth actually something and you can't protect it, maybe your work isn't ready for sell yet.

And from my point of view, Not all code is decompiled and Not all decompiled code is stolen so it is unlikely that the code one has it's stolen.

Let's calm down and don't make it look like " if you didn't buy it from me, it's likely to be stolen " kinda thing.

I bet there's a lot of guys that still wait for a real answer to " How can you tell if the code is decompiled or stolen ?" and will find a good answer quite useful .

 

I answered the question you asked me which was how to tell if code is stolen:

thrdel 2014.03.09 04:44


if you'd truly answer the original question about how one can tell if the code is or isn't stolen.

I gave you the answer to that and more, so now you lie and say your question was how to tell if it is "decompiled" or stolen. Obviously your a troll trying to be argumentative I'm not wasting any more time on you.

 
SDC:

I answered the question you asked me which was how to tell if code is stolen:

I gave you the answer to that and more, so now you lie and say your question was how to tell if it is "decompiled" or stolen. Obviously your a troll trying to be argumentative I'm not wasting any more time on you.


Calling me a liar and a troll tactic doesn't really work since you were faking answering a question NOT addressed to you just to get some attention and to call yourself "experienced programmer".So the troll in this case would be you !

On the other hand you couldn't give us a straight answer for how to spot a stolen code and neither for how to spot a decompiled code, which basically means you don't know. Why did you jumped to post answers you don't know ?

Maybe you should " start changing with the man in the mirror ". Look at you before you look at others ! Stop interfering and posting if you don't have an answer is always an option.

Have a good day.

 
Jhay82:
thanks for code have trouble putting code into.


I need to have a closer look at your code to understand what you wanted to do first, you know, logic first, code after.

There are sections that don't make sense, like this one :

   int Direction=0;//1=long, 11=avoid long, 2=short, 22=avoid short

   if(Day()!=5 || TradeOnFriday>0)   // do you want to trade if Day()=0 or Day()=6 ?
     {
      int cnt=0,total;
      total=OrdersTotal();
      if(total==0) OpeningDay=DayOfYear();
      OrderSelect(total-1,SELECT_BY_POS); // what are you trying to select here and why ?
      double LastPrice=OrderOpenPrice();

      OrderSelect(total,SELECT_BY_POS,MODE_TRADES); // what are you trying to select here ?

      //----------------------- ENTER POSITION BASED ON OPEN
      OrderWatcher=0;
      if(MAtype==0)
        {

then the entry looks like this :

      //----------------------- ENTER POSITION BASED ON OPEN
      OrderWatcher=0;
      if(MAtype==0)
        {
         if((iMA(NULL,0,MA_length,0,MODE_SMA,PRICE_OPEN,0)*(1+Percent/100))<Bid && Direction!=22 && (Bid>=(LastPrice+(CurrentPipStep*Point)) 
         || total==0)) // Go SHORT -> Only sell if >= 30 pips above previous position entry 
           {
            OrderSend(Symbol(),OP_SELL,Lots,Bid,slip,Bid+(Stoploss*Point),Bid-(TakeProfit*Point),0,MagicNumber,Red);
            OrderWatcher=1;
            Direction=2;
           }
         if((iMA(NULL,0,MA_length,0,MODE_SMA,PRICE_OPEN,0)*(1-Percent/100))>Ask && Direction!=11 && (Ask<=(LastPrice-(CurrentPipStep*Point)) 
         || total==0)) // Go LONG -> Only buy if >= 30 pips below previous position entry    

            //   if((iMA(NULL,0,MA_length,0,MODE_SMA,PRICE_OPEN,0)*(1-Percent/100))>Ask &&                  (Ask<=(LastPrice-(       PipStep*Point))||total==0))     

           {
            OrderSend(Symbol(),OP_BUY,Lots,Ask,slip,Ask-(Stoploss*Point),Ask+(TakeProfit*Point),0,MagicNumber,Blue);
            OrderWatcher=1;
            Direction=1;
           }
        }

      //----------------------- ENTER POSITION BASED ON HIGH/LOW

At this point Direction=0 since you have just above it int Direction=0;

if(your condition || total==0) will place an order even if your condition isn't true because of " ||total==0 " and it's the same for sell and buy. You end up with 2 orders at the same time. Is this what you want?

After the sell order, regardless if successful or not, Direction=2;

Then condition for Buy order is Direction!=11 ! It will never be 11, you just set it to 2 a couple of lines before .

Maybe it will help if you could explain the logic behind it, how you intended it to work.

Cheers.

 

thanks very much for help already

inspecting it.