Multiple take profits. - page 2

 
   //Lots = Lot1 + Lot2 + Lot3;
   int i;
   double pBid = MarketInfo(Symbol(),MODE_BID);  
   for( i=OrdersTotal()-1;i>=0;i--)  
     {    
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol()==Symbol() &&  OrderMagicNumber () == ........)
         {
          if(OrderType()==OP_BUY)
              {
               if((OrderLots()>.......) && pBid > ....)//first tp
                   {OrderClose(OrderTicket(),.....,OrderClosePrice(),Slippage.Pips * pips2points,Violet);}//Use Slippage correct
               if((OrderLots()>.......) && pBid > ....)//second
                   {OrderClose(OrderTicket(),....,OrderClosePrice(),Slippage.Pips * pips2points,Violet);}
               if(pBid > ...)  //last tp if you don't have set OrderTakeProfit() at tp3
                   {OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage.Pips * pips2points,Violet);}
              }
          ......sell trades          
         }
     }       
........ fill in make it complete
 

I know, why closes all lots one after another. I want to partial exit on Fibonacci tp1=38.2, tp2=61.8 and tp3=127.2%.

After TP1 partial close, my tp2 ant tp3 values becomes 0 and below if conditions becomes true because Bid> tp2 and tp3. But really Bid is < tp2 and tp3 and he have to wait while second condition would be true.

So, how to get tp2 and tp3 values from Fibonacci, that after first close order function they don't be zero?

Thank you.

if(OrderSymbol() == Symbol() && type==OP_BUY && Bid >= tp2 && OrderLots()==0.02)
//and
 
if(OrderSymbol() == Symbol() && type==OP_BUY && Bid>=tp3 && OrderLots()==0.01)


int start()
  {
  double p1,p2,tp1,tp2,tp3;
  string sp2,sp3;
  datetime h = TimeCurrent();
  string FibName = "a";

 //--------------------------fibonacci creates levels
  ObjectSet(FibName,OBJPROP_FIBOLEVELS,10); 
  ObjectSet(FibName,OBJPROP_FIRSTLEVEL+0,0.000); 
  ObjectSetFiboDescription(FibName,0,"0 %$");
  ObjectSet(FibName,OBJPROP_FIRSTLEVEL+1,0.382);
  ObjectSetFiboDescription(FibName,1,"38.2 %$");
  ObjectSet(FibName,OBJPROP_FIRSTLEVEL+2,0.5); 
  ObjectSetFiboDescription(FibName,2,"50 %$");
  ObjectSet(FibName,OBJPROP_FIRSTLEVEL+3,0.618); 
  ObjectSetFiboDescription(FibName,3,"61.8 %$");
  ObjectSet(FibName,OBJPROP_FIRSTLEVEL+4,0.786); 
  ObjectSetFiboDescription(FibName,4,"78.6 %$");
  ObjectSet(FibName,OBJPROP_FIRSTLEVEL+5,0.886); 
  ObjectSetFiboDescription(FibName,5,"88.6 %$");
    ObjectSet(FibName,OBJPROP_FIRSTLEVEL+6,1); 
  ObjectSetFiboDescription(FibName,6,"100 %$");
    ObjectSet(FibName,OBJPROP_FIRSTLEVEL+7,1.272); 
  ObjectSetFiboDescription(FibName,7,"127.2 %$");
    ObjectSet(FibName,OBJPROP_FIRSTLEVEL+8,1.414); 
  ObjectSetFiboDescription(FibName,8,"141.4 %$");
    ObjectSet(FibName,OBJPROP_FIRSTLEVEL+9,1.618); 
  ObjectSetFiboDescription(FibName,9,"161.8 %$");

//----------------------------- fibonacci actions
 p1=ObjectGet(FibName,OBJPROP_PRICE1);    //100% price
 p1=NormalizeDouble(StrToDouble(sp1),Digits);
  p2=ObjectGet(FibName,OBJPROP_PRICE2);    //0 % price
 sp2=DoubleToStr(p2,Digits);
 p2=NormalizeDouble(StrToDouble(sp2),Digits);
 tp1=(p2-p1)*0.618+p1;                  //38.2% price
 tp1=NormalizeDouble(tp1,Digits);

 //---------------Close TP1 on 38.2% fibonacci
int total = OrdersTotal(); 
for(int i=total-1;i>=0;i--)   
{  //1   
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
int type = OrderType();
if(OrderSymbol() == Symbol() && type==OP_BUY && Bid>=tp1 && OrderLots()==0.03)

{//2

OrderClose(OrderTicket(),0.01,MarketInfo(OrderSymbol(),MODE_BID),Digits); 
 p1=ObjectGet(FibName,OBJPROP_PRICE1);    //100% 
 sp1=DoubleToStr(p1,Digits);
 p1=NormalizeDouble(StrToDouble(sp1),Digits);
 p2=ObjectGet(FibName,OBJPROP_PRICE2);    //0 % 
 sp2=DoubleToStr(p2,Digits);
 p2=NormalizeDouble(StrToDouble(sp2),Digits);
 tp2=(p2-p1)*0.382+p1;                  //61.8 -TP2
 tp2=NormalizeDouble(tp2,Digits);            
 tp3=p1-((p2-p1)*0.272);               //127.2% - TP3
 tp3=NormalizeDouble(tp3,Digits);
 
 break;   //after this if condition tp2 and tp3 becomes 0 and other if conditions becomes true and closes my all orders.

   }  //2  
//---------------Close TP2 on 61.8% fibonacci
if(OrderSymbol() == Symbol() && type==OP_BUY && Bid >= tp2 && OrderLots()==0.02)
       
{//4
 p1=ObjectGet(FibName,OBJPROP_PRICE1);    //100% 
 sp1=DoubleToStr(p1,Digits);
 p1=NormalizeDouble(StrToDouble(sp1),Digits);
 p2=ObjectGet(FibName,OBJPROP_PRICE2);    //0 % 
 sp2=DoubleToStr(p2,Digits);
 p2=NormalizeDouble(StrToDouble(sp2),Digits);
 tp2=(p2-p1)*0.382+p1;                  //61.8 fib 
 tp2=NormalizeDouble(tp2,Digits);          
 tp3=p1-((p2-p1)*0.272);               //127.2% 
 tp3=NormalizeDouble(tp3,Digits);

OrderClose(OrderTicket(),0.01,MarketInfo(OrderSymbol(),MODE_BID),Digits); 

 break; }  //4 
//---------------Close TP3 on 127.2% fibonacci
 if(OrderSymbol() == Symbol() && type==OP_BUY && Bid>=tp3 && OrderLots()==0.01)
      
{//6
OrderClose(OrderTicket(),0.01,MarketInfo(OrderSymbol(),MODE_BID),Digits);    
  break;
}//6
    }//1
//----
   return(0);
  }
 
Eggo:

I know, why closes all lots one after another. I want to partial exit on Fibonacci tp1=38.2, tp2=61.8 and tp3=127.2%.

After TP1 partial close, my tp2 ant tp3 values becomes 0 and below if conditions becomes true because Bid> tp2 and tp3. But really Bid is < tp2 and tp3 and he have to wait while second condition would be true.

So, how to get tp2 and tp3 values from Fibonacci, that after first close order function they don't be zero?

Thank you.


Learn to read why don't you use MagicNumber in your code

Have you test the code for partial closing and is it working correctly ??

go make a code working for partial closing before you go work on other subject

test that code live on demo also...

 

I'll add MagicNumber later, without Magic number is easier to test it now.

Partial closing is working, when I write random price except of tp2 or tp3.

 
Eggo:

I'll add MagicNumber later, without Magic number is easier to test it now.

Partial closing is working, when I write random price except of tp2 or tp3.


Then it is not.....

why is it not working for tp2 and tp3 ?? check it

 

The biggest problem is how to identify if the order has been part closed already or not, and if it has, how many times ?

When I coded for that I didnt base it on the magic number because magic number cannot be modified.

Instead I modified the TP by +1 pip each time before I part closed the order. Then use the difference between original TP and current TP to identify how many times the order has been part closed, that allows you to set the target for the next part close based on how much the difference is. I use an EA managed soft TP so changing the hard TP has no effect on the strategy.

so for example, you want to part close every 30 pips,

if TP == original TP it has not been closed yet so target = openprice +30 pips

if TP== original TP+1 it has been closed once already so target = openprice + 60 pips

Put that difference in an integer and start it 1 you will see, target = openprice + (TPdifference*30*Point)

That system uses small amount of code and lends itself easily to an EA managing multiple simultanious orders.

 
//------Fibonacci moving function
int total1 = OrdersTotal(); 
for(int i1=total1-1;i1>=0;i1--)  
{     
      OrderSelect(i1, SELECT_BY_POS, MODE_TRADES);
     
      if ( OrderType() == OP_BUY && OrderSymbol() == Symbol()&& p2 > Bid /*&& Bid < tp1*/) // 
      {    
            p2=Low[0];
            ObjectMove(FibName, 1, h, p2); //Moves 0% 
            p2=ObjectGet(FibName,OBJPROP_PRICE2);    //0 % 
            sp2=DoubleToStr(p2,Digits);
            p2=NormalizeDouble(StrToDouble(sp2),Digits);
            tp2=(p2-p1)*0.382+p1;                  //61.8 fib 
            tp2=NormalizeDouble(tp2,Digits);           
            tp1=(p2-p1)*0.618+p1;                  //38.2% 
            tp1=NormalizeDouble(tp1,Digits);
            tp3=p1-((p2-p1)*0.272);               //127.2% 
            tp3=NormalizeDouble(tp3,Digits);
    //  }
      }
}

Explain what your code is doing every tick when it pass this part of code

and How is your Pivot working ?? Did you simply copy/paste indicatorlines in your EA ??