An Example of Trading Logic, with a Question - page 2

 
Roberto Jacobs:

You have kept track with this code.

ok so you are saying this is completely unnecessary then to use?

if(OrderSymbol() != Symbol() && OrderMagicNumber() != MagicNumber)continue;
 
Kenneth Parling:

ok so you are saying this is completely unnecessary then to use?

if(OrderSymbol() != Symbol() && OrderMagicNumber() != MagicNumber)continue;

I think that it is better to use

if(OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber)continue;
 
Kenneth Parling:

ok so you are saying this is completely unnecessary then to use?

Should not need to be used, the results will be the same as used or not. As in the conversation, if something is intended in the sentence, why do we have to ask again?

 
Keith Watford:

I think that it is better to use

that was my thought to and i'm using it myself and don't see any problems doing so

 
Kenneth Parling:

that was my thought to and i'm using it myself and don't see any problems doing so

It's up to you. If I always just want to find a simpler way.

 
Roberto Jacobs:

It's up to you. If I always just want to find a simpler way.

of course it's up to me...

thank's for you opinion

 

it depends on the context, too, I guess, because of things like order of execution, for example

...so, the way I'm using this is, I got an indicator that draws 17 Line Objects for one, two, or three durations in either direction, so there's up to 17x3x1=91 Line Objects at a time.  These Line Objects are in groups of 17 and ordered so by name that if I loop through them for order entry the previous line serves as stop and the next as target, which is why I'm trying to do this

for(i=1; i<=17; i++){                                                                                 //in a Sell this stays the same, except I use j instead of i
if(ObjectFind(LineObj[i]) == 0){                                                                      //in a Sell a different LineObj[] is used
       vM = NormalizeDouble(ObjectGetValueByShift(LineObj[i],0),Digits);                              //so like, when this LineObj[] is for BUY
       tmpsl = NormalizeDouble(ObjectGetValueByShift(LineObj[i-1],0),Digits);                         //...there'd be a SellLineObj[] for SELL
       tmptp = NormalizeDouble(ObjectGetValueByShift(LineObj[i+1],0),Digits);                         //...
       sl = tmpsl+(-0.5)*(tmptp-tmpsl);                                                               //...this becomes sl = tmpsl+0.5*(tmpsl-tmptp);
       tp = tmptp+0.5*(tmptp-tmpsl);                                                                  //...and...       tp = tmptp+(-0.5)*(tmpsl-tmptp); 
   if(OrderFind(MagicObj[i]) == false){
      if(Bid <= tmptp && Bid >= tmpsl && Bid >= vM){                                                  //...this becomes...   if(Bid <= tmpsl && Bid >= tmptp && Bid <= vM){
         if(OrderSend(Symbol(),OP_BUYLIMIT, PositionSize,vM,3,sl,tp,"",MagicObj[i],0,clrNONE)<0)      //...and the OP_BUYLIMIT becomes an OP_SELLLIMIT
            Print("Err (",GetLastError(), ") Open BuyLimit Price= ",vM, " SL= ",sl," TP= ",tp);}      //...                  ") Open SellLimit Price= "
      else if(Bid <= tmptp && Bid >= tmpsl && Bid <= vM){                                             //..                   if(Bid <= tmpsl && Bid >= tmptp && Bid >= vM){ 
         if(OrderSend(Symbol(),OP_BUYSTOP,PositionSize,vM,3,sl,tp,"",MagicObj[i],0,clrNONE) < 0)      //,OP_SELLSTOP,
            Print("Err (",GetLastError(), ") Open BuyStop Price= ", vM, " SL= ",sl," TP= ", tp);}}    //") Open SellStop Price= "
   else if (OrderFind(MagicObj[i]) == true){
      if(glbOrderType == OP_BUYLIMIT){                                                                //OP_SELLLIMIT){
         if(OrderSelect(glbOrderTicket, SELECT_BY_TICKET, MODE_TRADES)==true)
         if(vM != OrderOpenPrice())
         if(OrderModify(glbOrderTicket,vM,sl,tp,0,clrNONE) == false) 
            Print("Err (",GetLastError(), ") Modify BuyLimit Price= ",vM," SL= ",sl," TP= ",tp);       //") Modify SellLimit Price= "
         else if (glbOrderType != OP_BUYSTOP){
            if(Bid <= tmptp && Bid >= tmpsl && Bid <= vM){                                             //if(Bid <= tmpsl && Bid >= tmptp && Bid >= vM){
            if(OrderSend(Symbol(),OP_BUYSTOP,PositionSize,vM,3,sl,tp,"",MagicObj[i],0,clrNONE) < 0)    //
               Print("Err (",GetLastError(), ") Open BuyStop Price= ", vM, " SL= ",sl," TP= ", tp);}}} //") Open SellStop Price= "
      else if(glbOrderType == OP_BUYSTOP){                                                             //OP_SELLSTOP
         if(OrderSelect(glbOrderTicket, SELECT_BY_TICKET, MODE_TRADES)==true)
         if(vM != OrderOpenPrice())
         if(OrderModify(glbOrderTicket,vM,sl,tp,0,clrNONE) == false) 
            Print("Err (",GetLastError(), ") Modify BuyStop Price= ",vM," SL= ",sl," TP= ",tp);        //") Modify SellStop Price= "
         else if (glbOrderType != OP_BUYLIMIT){                                                        //!= OP_SELLLIMIT
            if(Bid <= tmptp && Bid >= tmpsl && Bid >= vM){                                             //if(Bid <= tmpsl && Bid >= tmptp && Bid <= vM){
            if(OrderSend(Symbol(),OP_BUYLIMIT,PositionSize,vM,3,sl,tp,"",MagicObj[i],0,clrNONE) < 0)   //OP_SELLLIMIT
               Print("Err (",GetLastError(), ") Open BuyStop Price= ", vM, " SL= ",sl," TP= ", tp);}}}}//") Open SellStop Price= "

like this...

Explanation-LineObj.jpg

 

...what I can't seem to figure out, probably for the lack of OOP skills, and programming skills in general, i suppose - is how to go about merging all these blocks into some kind of Order_Entry class, or some void(), i don't know, that can be called depending on the required direction and duration; because right now, I'm just using slightly modified blocks (like the one above, for every direction and every duration, so, essentially it's an almost identical code block copy pasted 6 times...well actually 12, because I also use conviction level(aggressive or conservative), and all the object names' arrays are string arrays that are ordered correctly the way the indicator draws them...so it's a naming heuristic, really, more than anything else, that seems to be doing the work here, and after all the declarations(about 70 lines) these 12 36-line blocks follow, and it becomes 560 lines of code...((( doesn't it seem like it should be maybe around 100 total, instead?

//

..right now I have a generic BUY block and a generic SELL block, the difference is that for every duration and conviction two characters are changed in the LineObj[] and MagicObj[] names themselves, so if it's an AggressiveDailyBuy[] and MagicAggressiveDailyBuy[] or a ConservativeWeeklyBuy[] and MagicConservativeWeeklyBuy[], it goes like, adb[] and madb[] or cwb[] and mcwb[]...

...so I declare them all and loop through all, but instead I could perhaps use some kind of methodology to declare them all but only loop through a generic one like a ConvDurDirBuy[] goes though adb, cdb, awb,cwb,... etc. using the correspoding values from the madb, mcdb, mawb,mcwb,... etc

...hm, what should I even google for this?

...there probably is a way to just have the declaration of the key I use to name all objects and have the code loop through them all...probably that's the way to get to 100 total lines instead...)