Help with simple issue?

 
extern int StopLoss = 200;
   
   int OnInit()
  {
  
   double StopLossLevel;
   double price= 1.87550;
   double lotsize1= 0.01;
   
   StopLossLevel = price+0.0050 - StopLoss*Point;

   Alert ("Welcome!");
   
   int ticket;
   ticket = OrderSend (Symbol(), OP_BUYSTOP,lotsize1,price,10,0,0,"Lot1",0,0,clrRed);
   
   int ticket2;
   ticket2 = OrderSend (Symbol(), OP_BUYSTOP,lotsize1,price+0.0050,10,StopLossLevel,0,"Lot2",0,0,clrRed);
   
   
//---
   return(INIT_SUCCEEDED);
  }

void OnTick()
  {
  double StopLossLevel;
   double price= 1.87550;
   double lotsize1= 0.01;
   
   StopLossLevel = price+0.0050 - StopLoss*Point;
  
 if(Ask > price+0.0050)
   {
  
  
    static bool res;
     res = OrderModify(ticket,price-0.0050,StopLossLevel,0,0,clrNONE);
     Alert ("ticket modified");
   
      int ticket3;
    res =  ticket3 = OrderSend (Symbol(), OP_BUYLIMIT,lotsize1,StopLossLevel-0.0002,10,0,0,"LotLimit1",0,0,clrRed);
   
   }
   
  }

Hello, 

I am still new to this so I am sure I am missing some basic stuff. I am getting an error: 'ticket' - undeclared identifier, and I am also getting stuck in infinate loops.


I have 2 orders open onInit and then I have want to modify one order and open another when the price reaches a certain level. I am not sure how to tell the code what the ticket is, can i find the number from the onInit and put it into the onTick? Or maybe its best to have it all within OnTick, but with this I also need to find out how to get these orders to go through just once. I thought static bool would solve this problem but I dont think I understand this right. Any help would be much appreciated! Thanks!



 

So this variable is within "OnInit()" scop event handler function,into the "OnTick()" it wont be detected and cause of the error,you could move it as global variable before "OnInit()".

For checking once you could do this :

 static bool checked=false;
 if(!checked && Ask > price+0.0050)
   {
     checked=true;
  
     bool res;
     res = OrderModify(ticket,price-0.0050,StopLossLevel,0,0,clrNONE);
     Alert ("ticket modified");
   
     int ticket3;
     res =  ticket3 = OrderSend (Symbol(), OP_BUYLIMIT,lotsize1,StopLossLevel-0.0002,10,0,0,"LotLimit1",0,0,clrRed);
   }

Really i dont know what your purposes of your main strategy rule doing is.

 
Mehrdad Jeddi:

So this variable is within "OnInit()" scop event handler function,into the "OnTick()" it wont be detected and cause of the error,you could move it as global variable before "OnInit()".

For checking once you could do this :

Really i dont know what your purposes of your main strategy rule doing is.

Thanks so much for your suggestion! The idea for the one time order works perfectly. I have tried putting the other orders before the OnInit however I get a bunch of error messages saying declaration without type for the tickets and alerts. 


Would there be a way to put it within the 'OnTick()' body with the same code as you have suggested but not being contingent on a price? for example rather than: if (Ask > price), is there a way to say: if not opened? for example or, if program started?


I hope that makes sense. Thanks again!

 
doctorbeppo:

I have tried putting the other orders before the OnInit however I get a bunch of error messages saying declaration without type for the tickets and alerts. 

So in this case maybe you forgot to set its type of each variable,could you share that code how you declared it?

doctorbeppo:
Would there be a way to put it within the 'OnTick()' body with the same code as you have suggested but not being contingent on a price? for example rather than: if (Ask > price), is there a way to say: if not opened? for example or, if program started?

I dont get this part?

 
Mehrdad Jeddi:

So in this case maybe you forgot to set its type of each variable,could you share that code how you declared it?

I dont get this part?

  static int ticket;
   ticket = OrderSend (Symbol(), OP_BUYSTOP,lotsize1,price,10,0,0,"Lot1",0,0,clrRed);
   
   static int ticket2;
   ticket2 = OrderSend (Symbol(), OP_BUYSTOP,lotsize1,price+0.0050,10,StopLossLevel,0,"Lot2",0,0,clrRed);
  
   
   int OnInit()

Here is the code for the tickets before the OnInit() 

Error messages - declaration without type

 
doctorbeppo:

Here is the code for the tickets before the OnInit() 

Error messages - declaration without type

So you should declare as below:

 int ticket,ticket2;
   
 int OnInit()
   {
   ticket = OrderSend (Symbol(), OP_BUYSTOP,lotsize1,price,10,0,0,"Lot1",0,0,clrRed);
   
   ticket2 = OrderSend (Symbol(), OP_BUYSTOP,lotsize1,price+0.0050,10,StopLossLevel,0,"Lot2",0,0,clrRed);
   }
 
Mehrdad Jeddi:

So you should declare as below:

You are a hero sir. It's all now working as it should. 


Thankyou!

 
doctorbeppo:

You are a hero sir. It's all now working as it should. 


Thankyou!

You're welcome.

Reason: