Download MetaTrader 5

Help WIth Code For Simulated Market Orders

To add comments, please log in or register
SGLJ1967
8
SGLJ1967  

I am hoping you can help me with a simple coding issue (I just think I'm to close to the problem). I am trying to use a Custom Function to do simulated trading and if the simulated market order is a WINNER or LOSER will determine if my EA places trades, etc.

My problem is storing the value of the simulated market order's entry price, exit price and the ultimate variable that is returned (Outcome). I don't want the value of the entry price (BUYEnter or SELLEnter), exit price (BUYExit, SELLExit) or Outcome to change until a new simulated market order is triggered.

I know arrays, etc. are the key, but honestly, I’m clueless.

C

string Query()
{
bool BUY, SELL, BUYEXIT, SELLEXIT;
double BUYEnter,  BUYExit, SELLEnter, SELLExit, GAIN;

doubleSELLMetric = iLow(Symbol(), PERIOD_H1, iLowest(Symbol(), PERIOD_H1, MODE_LOW, 12, 1));
double BUYMetric = iHigh(Symbol(), PERIOD_H1, iHighest(Symbol(), PERIOD_H1, MODE_HIGH, 12, 1));

double ExitBUY = iLow(Symbol(), PERIOD_H1, iLowest(Symbol(), PERIOD_H1, MODE_LOW, 3, 1));
double ExitSELL = iHigh(Symbol(), PERIOD_H1, iHighest(Symbol(), PERIOD_H1, MODE_HIGH, 3, 1));

if(BUY == false && Ask > BUYMetric) BUYEnter = BUYMetric; if( BUY == true && Bid < ExitBUY) BUYExit = ExitBUY;  
if(SELL == false && Bid < SELLMetric) SELLEnter = SELLMetric; if(SELL == true && Ask > ExitSELL) SELLExit = ExitSELL;  

if(BUYEnter > 0 && SELL == false) BUY = true; if(SELLEnter > 0 && BUY == false) SELL = true;
if(BUY == true && BUYExit > 0) BUYEXIT = true; if(SELL == true && SELLExit > 0) SELLEXIT = true;

if(BUYEXIT == true)  GAIN = BUYExit – BUYEnter; if(SELLEXIT == true)  GAIN = SELLEnter – SELLExit;

if(GAIN >= 0) Outcome = “WINNER”; if(GAIN < 0) Outcome = “LOSER”;

return(Outcome);
}


an someone help me, please?

whroeder1
16755
whroeder1  

SGLJ1967:

I don't want the value of the entry price (BUYEnter or SELLEnter), exit price (BUYExit, SELLExit) or Outcome to change until a new simulated market order is triggered.

I know arrays, etc. are the key, but honestly, I’m clueless.

  1. Only static and globally declared variables retain their values between calls.
  2. Obviously. You need arrays if you're going to simulate multiple concurrent orders (subject to #1.)
To add comments, please log in or register