Hi there,
A newbie programmer here. I've just been tinkering around with this indicator attached below: just an ordinary 2 MA crossover indi which prints upward- and downward-pointing arrows when the MA crossover happens.
What I wanted to achieve is very simple: connecting the indicator to an EA. The EA should place buy orders the very moment the indicator prints an up arrow and should place sell orders the very moment the indicator prints a down arrow.
I wrote the EA, with the iCustom() function. It seems good to me, however, when running the code, the strategy tester halts. I'm not getting any error messages in the Journal though. As you can see in the indicator file, it has a boolean AlertOn parameter that is set to True by default. When running my EA in the strategy tester, I get these Alerts in the Journal tab correctly, therefore the indicator runs properly.
I'm not sure where I might have messed up. I thought this should be a fairly easy practice task, just reading the buffers of an already-done indi, and placing a buy/sell order depending on the value of that indi buffer.
Any suggestion or help would be greatly appreciated!!
The full EA code is below (note that the indi has plenty of inputs):
A newbie programmer here. I've just been tinkering around with this indicator attached below: just an ordinary 2 MA crossover indi which prints upward- and downward-pointing arrows when the MA crossover happens.
What I wanted to achieve is very simple: connecting the indicator to an EA. The EA should place buy orders the very moment the indicator prints an up arrow and should place sell orders the very moment the indicator prints a down arrow.
I wrote the EA, with the iCustom() function. It seems good to me, however, when running the code, the strategy tester halts. I'm not getting any error messages in the Journal though. As you can see in the indicator file, it has a boolean AlertOn parameter that is set to True by default. When running my EA in the strategy tester, I get these Alerts in the Journal tab correctly, therefore the indicator runs properly.
I'm not sure where I might have messed up. I thought this should be a fairly easy practice task, just reading the buffers of an already-done indi, and placing a buy/sell order depending on the value of that indi buffer.
Any suggestion or help would be greatly appreciated!!
The full EA code is below (note that the indi has plenty of inputs):
Inserted Code
extern double Lots = 0.01; double UpArrow; double DownArrow; string filename = WindowExpertName(); int OnInit() { return(INIT_SUCCEEDED); } void OnTick() { UpArrow = iCustom(_Symbol,_Period,"2MA CrossoverWithPrice", "First Moving Average", 5, "0=sma, 1=ema, 2=smma, 3=lwma", 1, " 0=close, 1=open, 2=high, 3=low,", " 4=median(high+low)/2,", " 5=typical(high+low+close)/3,", " 6=weighted(high+low+close+close)/4", 0, "--------------------------------------------", "Second Moving Average", 10, "0=sma, 1=ema, 2=smma, 3=lwma", 1, " 0=close, 1=open, 2=high, 3=low,", " 4=median(high+low)/2,", " 5=typical(high+low+close)/3,", " 6=weighted(high+low+close+close)/4", 0, "--------------------------------------------", "Arrow Type", "0=Thick, 1=Thin, 2=Hollow, 3=Round", "4=Fractal, 5=Diagonal Thin", "6=Diagonal Thick, 7=Diagonal Hollow", "8=Thumb, 9=Finger", 2, "--------------------------------------------", "turn on Alert = true; turn off = false", false, "--------------------------------------------", "send Email Alert = true; turn off = false", false, 0,0); // if UpArrow has any "non-infinite", i.e. non-INT_MAX value, it means the indi has placed an up-arrow if(UpArrow != INT_MAX) { // only one trade at a time if(OrdersTotal() == 0) { int buyticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,filename,12345,0,Green); if(buyticket < 0) { Alert("OrderSend Error: ", GetLastError()); } else { Alert("Order Sent Successfully, Ticket # is: " + string(buyticket)); } } } }
Attached File(s)
2MA CrossoverWithPrice.mq4
17 KB
|
155 downloads