Ratchet Stop?

 

hi Guys,

Im not sure if its called a ratchet stop but im looking to do a stop loss that will jump to Break even when 100 pips has been hit and then to 100 when 200 has been hit and to do this up to 5 levels.


I have messed around with a couple of ideas and the problem is the SL keeps moving up and back down again endlessly modifiying because both step 1 and step 2 are true for example.

I tried setting bool flags that when step 2 ==true then step 1 = false but no joy.

Does anyone have an idea how to code this? your help will be much appreciated


thanx

 

if(Profit>300) moveStop(200);return;
if(Profit>200) moveStop(100);return;
if(Profit>100) moveStop(0); return;
//if your are in a loop you can also use continue instead of return to skip the following modifications

int CurrProfit=(OrderOpenPrice()-OrderClosePrice()) * point2pip;
int currLevel=CurrProfit- (CurrProfit%100);
double newStopLoss=OrderOpenPrice()+ ((currLevel-100)*pip2point);

this looks way better, is more dynamically and should work for buyorders. There could be a logical error in the code, it's already late here. 

 

thanx zzuegg, your help is very much appreciated :)

 

Hi Guys...im still at a loss here...i tried to use some elements from zzuegg's comment but my skills aren't good enough to make it work... here is what I tried with no luck I then reference the special function in the start function of the code but its no go.

it does not move the stop in 100pip chunks ...any one have an idea that will get this to work? I REALLY need this to work in my EA. :(


thanx

void check_stops()
{
///////////////////
CurrProfit=NormalizeDouble((OrderOpenPrice()-Bid),2) ;


if(CurrProfit>100&&CurrProfit<200){step1=true;}
if(CurrProfit>200&&CurrProfit<300){step1=false;step2=true;}
if(CurrProfit>300&&CurrProfit<400){step1=false;step2=false;step3=true;}
//////////////////
OrderSelect(cnt, SELECT_BY_POS);   
     int mode=OrderType();    
        if ( OrderSymbol()==Symbol() ) 
        {
            if ( mode==OP_BUY )
            {
if(step1==true){BuyStop = OrderOpenPrice();
               OrderModify(OrderTicket(),OrderOpenPrice(),
                           NormalizeDouble(BuyStop, digit),
                           OrderTakeProfit(),0,LightGreen);
                           step1=false;}

//////////////////
if(step2==true){BuyStop = OrderOpenPrice()+100*Point;
               OrderModify(OrderTicket(),OrderOpenPrice(),
                           NormalizeDouble(BuyStop, digit),
                           OrderTakeProfit(),0,LightGreen);
                           step1=false;step2=false;}

//////////////////
if(step3==true){BuyStop = OrderOpenPrice()+200*Point;
               OrderModify(OrderTicket(),OrderOpenPrice(),
                           NormalizeDouble(BuyStop, digit),
                           OrderTakeProfit(),0,LightGreen);
                           step1=false;step2=false;step3=false;}
             }              
//////////////////
if ( mode==OP_SELL )
            {
           if(step1==true){SellStop = OrderOpenPrice();
               OrderModify(OrderTicket(),OrderOpenPrice(),
                                  NormalizeDouble(SellStop, digit),
                                  OrderTakeProfit(),0,Yellow);
                                   step1=false;}
                                   
                 if(step2==true){SellStop = OrderOpenPrice()-100*Point;
               OrderModify(OrderTicket(),OrderOpenPrice(),
                                  NormalizeDouble(SellStop, digit),
                                  OrderTakeProfit(),0,Yellow);
                                   step1=false;step2=false;}  
                                   
                                   if(step3==true){SellStop = OrderOpenPrice()-200*Point;
               OrderModify(OrderTicket(),OrderOpenPrice(),
                                  NormalizeDouble(SellStop, digit),
                                  OrderTakeProfit(),0,Yellow);
                                   step1=false;step2=false;step3=false;}               
}
}
////////////////////////
}
 

I have a question for you . . .

void check_stops()
{
///////////////////

CurrProfit=NormalizeDouble((OrderOpenPrice()-Bid),2) ;  //  <-- at this point have you already selected an order ?  maybe this line  and the next 3 lines should be moved to . . . 


if(CurrProfit>100&&CurrProfit<200){step1=true;}
if(CurrProfit>200&&CurrProfit<300){step1=false;step2=true;}
if(CurrProfit>300&&CurrProfit<400){step1=false;step2=false;step3=true;}
//////////////////
OrderSelect(cnt, SELECT_BY_POS);   
     int mode=OrderType();    
        if ( OrderSymbol()==Symbol() ) 
        {
            if ( mode==OP_BUY )
            {
                                                                    //  <-------   . . . . .  here ?

if(step1==true){BuyStop = OrderOpenPrice();
               OrderModify(OrderTicket(),OrderOpenPrice(),
                           NormalizeDouble(BuyStop, digit),
                           OrderTakeProfit(),0,LightGreen);
                           step1=false;}
 
thank you, you r help is much appreciated. It works and pushed my EAs profit factor from 1.75 up to 3.88... thanx Raptor for the help :)
Reason: