A trailing take profit for my magic and pair (the group)

Back to topics list To post a new topic, please log in or register
avatar
25
sdoppke 2015.09.04 15:28
 
 {  
   if (DB_Profit>=DB_Target);DBFloor=DB_Target;DB_Target=DB_Target*DB_Target_Factor;
   if (DB_Profit>=DB_Target);
   else if (DB_Profit<DBFloor);
  }
   j=OrdersTotal()-1;
   for (i=j;i>=0;i--)
    {
     OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
     RefreshRates();
     if(OrderMagicNumber()==DB_Magic && OrderSymbol()==Symbol())
      OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,Blue);
    }

I'm hoping to get help with my code here.  The goal is to have a sort of trailing take profit for my group(magic and pair).  As the total profit for the magic and pair (DB_Profit) moves past my target (DB_Tartget) the target becomes the floor (DBFloor).  If the total profit (DB_Profit) were to revert back down < the floor (DBFloor) the group (magic and pair) would close.  When the total profit moves past the target (as stated above) and the floor becomes the target the target is then changed (or moved up) to DB_Target*DB_Target_Factor (i.e. $$10*1.5=%15).  I am learning fast but I cannot figure out this loop. 

Would anyone be willing to help and point me in to the right direction? 

Thanks in advance for any help

SD.


                                                                                                                                                                                                                                                                                             
avatar
25
sdoppke 2015.09.04 17:13 #
 

I thought I would show my modifications, but  no luck so far.  The trades close as soon as they open.


if (DB_Profit>=DB_Target)DBFloor=DB_Target;
   if (DB_Profit>=DB_Target)DB_Target=DB_Target*DB_Target_Factor;
   else if (DBFloor!=0 && DB_Profit<DBFloor);
   j=OrdersTotal()-1;
   for (i=j;i>=0;i--)
    {
     OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
     RefreshRates();
     if(OrderMagicNumber()==DB_Magic && OrderSymbol()==Symbol())
      OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,Blue);
avatar
25
sdoppke 2015.09.04 20:56 #
 
 if (Bolli_Profit>=Bolli_Target){BolliFloor=Bolli_Target && Bolli_Target==Bolli_Target*Bolli_Target_Factor;}
   if (BolliFloor!=0 && Bolli_Profit<BolliFloor)
   {j=OrdersTotal()-1;
   for (i=j;i>=0;i--)
    {
     OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
     RefreshRates();
     if(OrderMagicNumber()==Bolli_Magic && OrderSymbol()==Symbol())
      OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,Blue);}
    }

I have been able to have it keep the orders open but I cannot get the DBFloor to receive a value, so they just stay open.  


Let me know if you have any ideas.

avatar
25
sdoppke 2015.09.04 22:25 #
 
I'm thinking that the target needs to increment (using "for"??) I'm not sure how to start that.
avatar
Moderator
3418
GumRai 2015.09.05 00:53 #
 
   if(Bolli_Profit>=Bolli_Target && Bolli_Profit-BolliFloor>Bolli_Target )
      BolliFloor=Bolli_Profit-Bolli_Target;
   if(BolliFloor!=0 && Bolli_Profit<BolliFloor)
     {
      //Code to close orders
     }
Not totally sure, but I think you need something like this
avatar
25
sdoppke 2015.09.09 18:43 #
 
GumRai thanks again for you help.  That helped to lead me in the right direction.
Back to topics list  

To add comments, please log in or register