wrong calculations

 

hello;

in the below code i have put r3 =112..but in metatrader stratagy tester sl for order is not placed accourdingly that ..i have tried every thing..please have a see and help wat should i do..??

sl should be placed 11.2 pips below but it is palcing it only 3 pips down...

//+------------------------------------------------------------------+
//|                                                        fixed.mq4 |
//|                        
//+------------------------------------------------------------------+
#include <stdlib.mqh>
double v2=2.2,v3=4.8;
int vfot;
int magic=111;
double slp=300,tpp=150,r1,r2;
double l1,l2;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  
  
  if(OrdersTotal()==1 && poc()==1)
  {
  OrderSelect(0,SELECT_BY_POS);
  OrderDelete(OrderTicket());
  }
  if(OrdersTotal()==0)
  OrderSend(Symbol(),0,1,Ask,3,0,0,NULL);
  OrderSelect(0,SELECT_BY_POS);
  vfot=OrderType();
  
if(vfot==0)
{
l1=OrderOpenPrice()+tpp*Point;
l2=OrderOpenPrice()-slp*Point;
//Print(l2);
}
 else if(vfot==1)
{
l1=OrderOpenPrice()-tpp*Point;
l2=OrderOpenPrice()+slp*Point;
}
int poc=poc();
/*if(OrderStopLoss()!=0)
{
slp=MathAbs(OrderStopLoss()-OrderOpenPrice());
if(StringFind(OrderSymbol(),"JPY",0)>=0)
slp=slp*100;
else if(StringFind(OrderSymbol(),"JPY",0)<0)
slp=slp*10000;
r1=slp/2;
r2=slp/4;
double r3=((r1+r2)/2);
tpp=slp/2;
if(vfot==0)
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()+Point*tpp,NULL);
if(vfot==1)
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()-Point*tpp,NULL);
Print(tpp,slp);
}
*/
r1=slp/2;
r2=slp/4;
int r3=112;
//NormalizeDouble(r3,2);
//Print(r1,r2,r3);

if(OrdersTotal()==1 && poc==0)
{
if(vfot==0)

OrderSend(Symbol(),5,v2,NormalizeDouble(OrderOpenPrice()-r1*Point,5),3,0,0);
if(vfot==1)
OrderSend(Symbol(),4,v2,NormalizeDouble(OrderOpenPrice()+r1*Point,5),3,0,0);
}

if(OrdersTotal()==2 && poc==0)
{
OrderSelect(0,SELECT_BY_POS);
int vfot=OrderType();
if(vfot==0)
{
double p=NormalizeDouble(OrderOpenPrice()-r3*Point,5);
Print(r3*Point);
OrderSend(Symbol(),4,v3,NormalizeDouble(OrderOpenPrice()-r2*Point,5),3,p,0,NULL); ---------here is problem line
}
if(vfot==1)
{
OrderSend(Symbol(),5,v3,NormalizeDouble(OrderOpenPrice()+r2*Point,5),3,NormalizeDouble(OrderOpenPrice()+r3*Point,5),0,NULL);

}}
if(OrdersTotal()==3)
{
if(vfot==0)
OrderSend(Symbol(),5,v3,NormalizeDouble(OrderOpenPrice()-r3*Point,5),3,NormalizeDouble(OrderOpenPrice()-r2*Point,5),0,NULL);
if(vfot==1)
OrderSend(Symbol(),4,v3,NormalizeDouble(OrderOpenPrice()+r3*Point,5),3,NormalizeDouble(OrderOpenPrice()+r2*Point,5),0,NULL);
}
if(OrdersTotal()==2 && poc==0)
{
if(CompareDoubles(Close[0],l2))
closeall();
}

if(OrdersTotal()==3 && poc==0)
{
if(CompareDoubles(Close[0],OrderOpenPrice()))
closeall();
}

if(OrdersTotal()==3 && poc==0)
{
if(CompareDoubles(Close[0],l2))
closeall();
}

return(0);
  }
  
  int poc()
{
int pocf=0,i;
for(i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS);
if(OrderType()==OP_BUYSTOP ||OrderType()==OP_SELLSTOP)
{
pocf++;
}
}
return(pocf);
}

void closeall()
{
int j;
for(j=OrdersTotal()-1;j>=0;j--)
{
OrderSelect(j,SELECT_BY_POS);

if(OrderType()==OP_BUY)
OrderClose(OrderTicket(),OrderLots(),Bid,3);
if(OrderType()==OP_SELL)
OrderClose(OrderTicket(),OrderLots(),Ask,3);
if(OrderType()==OP_BUYSTOP)
OrderDelete(OrderTicket());
if(OrderType()==OP_SELLSTOP)
OrderDelete(OrderTicket());
if(OrderType()==OP_BUYLIMIT)
OrderDelete(OrderTicket());
if(OrderType()==OP_SELLLIMIT)
OrderDelete(OrderTicket());
}

}
 

Hello Ankit,


Do you want to declare a variable with a fixed permanent stop loss or do you want to modify the stop loss of an order with a variable's value once the orders been sent?

Either way you're prolly thinkin' "I want to declare a variable". This is my impression presently.


Thank you

 
sir i just wanted to place a stop order with permanent stop of 11.2 pips..i have a five digit broker...so i put r3 as 112 pips...but mt4 always placed it at 3 pips..the value of r3 doesnt change i have cnfirmed by print()
 
in the above snip. sl should be at 1.29260
 
ankit29030:
sir i just wanted to place a stop order with permanent stop of 11.2 pips..i have a five digit broker...so i put r3 as 112 pips...but mt4 always placed it at 3 pips..the value of r3 doesnt change i have cnfirmed by print()

Ankit,

Aight, you can try something like this-

double SL=112;

// if conditions are met...

OrderSend(Symbol(),OP_BUY,0.10,Ask,30,SL,0,"",12345,0,Blue);

I'm thinkin' your other code is getting involved with 'r3'. Also, consider writing code as simple as possible so you don't get overwhelmed by code. Single comments announcing purpose of code blocks below should be above each code block to assist your eyes as you scan your code.


Thank you

 
does this happen?? code interference???
 
ankit29030:
does this happen?? code interference???

Please clearly explain your meaning.


Thank you

 
i mean variables of same identifier from different ea interfare or interchange values
 

Ankit,

Only way to find out if separate EA is interfering with this EA is to run one EA and check for problems, then run both EAs and check for problems.


Thank you

 
ankit29030:

hello;

in the below code i have put r3 =112..but in metatrader stratagy tester sl for order is not placed accourdingly that ..i have tried every thing..please have a see and help wat should i do..??

sl should be placed 11.2 pips below but it is palcing it only 3 pips down...

Can you please use  these  Trade Constants  I know what OP_BUYSTOP means  I don't know what 4 means . . .

What was your spread ? 

 
RaptorUK:

Can you please use  these  Trade Constants  I know what OP_BUYSTOP means  I don't know what 4 means . . .

What was your spread ? 


i have a ecn account and spread on usd/jpy are less than 1.5....

OP_BUYSTOP is equal to integer 4 and OP_SELLSTOP is equal to 5... 

Reason: