Repeating process at different prices?

To add comments, please log in or register
doctorbeppo
44
doctorbeppo  

At the moment I have some very overly convoluted code which is repeating a process at different prices with different ticket numbers etc. I am a bit lost as to finding out a way to get the code to repeat, but at a new price (if this is possible?) Hopefully it is clear from what I have posted. The idea is simple, there is a Buy Stop above an open Buy, and when the Buy Stop is reached, the two -now open- positions share the same stop loss. When the stop loss is hit, a new Buy is opened and the process repeats from here. At the moment I am manually writing all new code for each part which is confusing and will not be very useful when I am trying to figure out the next steps of this module. 


Any help or guidance is greatly appreciated.

int ticket,ticket2,ticket3, ticket4,ticket5,ticket6, ticket7;

double SLP;
double price= 1.78600;
double price2 = price + 0.0050;
double lotsize1= 0.1;
//double price2 = SLP +0.0002
  
extern int StopLoss = 200;


   int OnInit()  
 {
   SLP = price2 - StopLoss*Point;
   
   Alert ("Welcome!");
      
    ticket = OrderSend (Symbol(), OP_BUYSTOP,lotsize1,price,10,0,0,"Lot1",0,0,clrRed);
   
    ticket2 = OrderSend (Symbol(), OP_BUYSTOP,lotsize1,price2,10,SLP,0,"Lot2",0,0,clrRed);

return(INIT_SUCCEEDED);
  }
  
   void OnTick()
  {
 
// double newlevel= SLP + 0.0032;
 //double newlevel2 = newlevel + 0.003;
// double newlevelb = SLP-0.0022;
 
 double price3 = SLP+0.0002;
 double price4 = price3+0.0050;
 double SLP2 = price4-0.0020;
 double price5 = SLP2+0.0002;
 double price6 = price5+0.0050;
 double SLP3 = price6-0.0020;
 double price7 = SLP3+0.0002;
 
{
 static bool checked=false;
   if(!checked && Ask > price+0.0050)
   {
    checked=true;
  
bool res = OrderModify(ticket,0,SLP,0,0,clrNONE);
if(res)Alert ("ticket modified");

 ticket3 = OrderSend (Symbol(), OP_BUYLIMIT,lotsize1,price3,10,0,0,"LotLimit1",0,0,clrRed);

}}
{
static bool checked2=false;
   if(!checked2 && OrderSelect(ticket3,SELECT_BY_TICKET) && OrderType() == OP_BUY)
   {
    checked2=true;
    
ticket4 = OrderSend (Symbol(), OP_BUYSTOP,lotsize1,price4,10,SLP2,0,"Lot3",0,0,clrRed);
if(ticket4>0)Alert ("ticket4 opened");   
}}
  
{
static bool checked3=false;
   if(!checked3 && OrderSelect(ticket4,SELECT_BY_TICKET) && OrderType() == OP_BUY)
   {
    checked3=true;
  
bool res = OrderModify(ticket3,0,SLP2,0,0,clrNONE);
if(res)Alert ("ticket modified");

ticket5 = OrderSend (Symbol(), OP_BUYLIMIT,lotsize1,price5,10,0,0,"Lot4",0,0,clrRed);
   
     }}
     
     {
static bool checked4=false;
   if(!checked4 && OrderSelect(ticket5,SELECT_BY_TICKET) && OrderType() == OP_BUY)
   {
    checked4=true;
    
ticket6 = OrderSend (Symbol(), OP_BUYSTOP,lotsize1,price6,10,SLP3,0,"Lot3",0,0,clrRed);
if(ticket6>0)Alert ("ticket4 opened");   

 }}
{
static bool checked5=false;
   if(!checked5 && OrderSelect(ticket6,SELECT_BY_TICKET) && OrderType() == OP_BUY)
   {
    checked5=true;
  
bool res = OrderModify(ticket5,0,SLP3,0,0,clrNONE);
if(res)Alert ("ticket modified");

ticket7 = OrderSend (Symbol(), OP_BUYLIMIT,lotsize1,price7,10,0,0,"Lot4",0,0,clrRed);
      
     }}
     
     }
     
To add comments, please log in or register