Pips - page 2

 
Keith Watford:

The best way to learn is try, even though you make mistakes.

You will unlikely find anyone here willing to write the code for you, because most people do not learn from that.

We have had many new coders ask for examples and then they are back with the same problems over and over again.

Ok i will try it... 
 
extern double Current_Lots  = 0.01,
              PipsRange     = 0.00020; // 2 pips

double        Sell_Run_Price,
              Buy_Run_Price,  
              


int init()
{
   Buy_Run_Price = Ask; // First Open buy
   int ticket = OrderSend(Symbol(),OP_BUY,Current_Lots,Buy_Run_Price ,2,0,0,"Ea..",0,0, Blue);  // 1. Open order Buy
     
   return(0);
}

int start(){
  
  Buy_Run_Price = Ask; 
  OrderCheck(Buy_Run_Price); // Check whether order is buy or sell
  if () //If Total profit is $2 close all order
      return(0);
   
}
     

double OrderCheck(double BuyOrSell){

   if(OrderType() == OP_BUY) {
      BuyFunction(BuyOrSell);} // if order is buy then go to buy function
   else if(OrderType() == OP_SELL) {
      SellFunction (BuyOrSell);} // if order is sell then go to sell function
   return(BuyOrSell);
}

double BuyFunction(double Current_price){ // buy function
   if(Current_price >= Current_price + PipsRange){ // If Current running price is higher 2 pips then Open Buy with lot 0.01
      OrderSend(Symbol(),OP_BUY,Current_Lots,Current_price ,2,0,0,"Ea..",0,0, Blue);}
   else if(Current_price <= Current_price - PipsRange){ // Else if Current running price is lower 2 pips then Open Sell with lot 0.01 +0.01 
      OrderSend(Symbol(),OP_SELL,Current_Lots+0.01,Current_price ,2,0,0,"Ea..",0,0, Red);
      return(Current_price);}
}

double SellFunction(double Current_price){ // sell function
   if(Current_price <= Current_price - PipsRange){ // If Current running price is lower 2 pips then Open sell with lot 0.01
      OrderSend(Symbol(),OP_SELL,Current_Lots,Current_price ,2,0,0,"Ea..",0,0, Red);}
      else if(Current_price >= Current_price + PipsRange){ // Else if Current running price is higher 2 pips then Open Buy with lot 0.01 +0.01 
      OrderSend(Symbol(),OP_BUY,Current_Lots+0.01,Current_price ,2,0,0,"Ea..",0,0, Blue);
      return(Current_price);}
}

int deinit()
{
   return(0);
}



Keith Watford, can you help me to resolve this code. Thanks
   




 

Hello,

the first thing that you should do is avoid the old functions init, start, deinit.

Click on New (top left of the editor window) and Expert Advisor and a template using the modern functions will load.

Never open a trade in OnInit(), all data may not be loaded yet.

Why are you passing the current Ask price to functions?

OrderType() //There must be an OrderSelect() first

Make a logic plan, if your current code worked, it would be opening orders nearly every tick and you don't want that

 
Keith Watford:

Hello,

the first thing that you should do is avoid the old functions init, start, deinit.

Click on New (top left of the editor window) and Expert Advisor and a template using the modern functions will load.

Never open a trade in OnInit(), all data may not be loaded yet.

Why are you passing the current Ask price to functions?

Make a logic plan, if your current code worked, it would be opening orders nearly every tick and you don't want that

***Click on New (top left of the editor window) and Expert Advisor and a template using the modern functions will load.

R : You mean i create a new one  and copy paste my coding to new page? 

***Never open a trade in OnInit(), all data may not be loaded yet.

R: You mean i always coding on int start() right? 

Why are you passing the current Ask price to functions?

R : i will try orderselect first and and use ordetype() 

OrderType() //There must be an OrderSelect() first

Make a logic plan, if your current code worked, it would be opening orders nearly every tick and you don't want that

 
Kucubi:

Make a logic plan, if your current code worked, it would be opening orders nearly every tick and you don't want that

***Click on New (top left of the editor window) and Expert Advisor and a template using the modern functions will load.

R : You mean i create a new one  and copy paste my coding to new page? 

No, your code is not doing what you want. Write out what you want the EA to do, if you can do flow charts even better

You then have the steps that you will need to follow, then code each step 1 at a time

***Never open a trade in OnInit(), all data may not be loaded yet.

R: You mean i always coding on int start() right? 

Modern function is OnTick() not start()

Why are you passing the current Ask price to functions?

R : i will try orderselect first and and use ordetype() 

This is where you need the logic plan/flowchart. Your existing code, if it was working would open multiple orders and not a good idea. Remember if you have more than 1 open order, your plan has to include how you will deal with all orders.

Reason: