Hey there,
I'm having real problems trying to root out the cause of my codes failures.
I'm trying to simply create an ea that places a buy order if it is above three SMA (a 60 on the 5m, a 60 on the 1h, and 60 on the 4h), or places a sell order if it is below. This is not the full ea I'll be using, this is the starting process for a better plan. But I can't get past this first road block, as whenever I run my script it doesn't seem to take notice of my buy/sell conditions, and simply places buy orders throughout no matter where the current price is (above or below any of the SMA). It also never generates sell orders.
I hope I explained this correctly, and any help will be greatly appreciated!
Many thanks!
Cord
The code -
EDIT:
Ok, I have tried (I am very new to coding, started yesterday) to refine the code so it's smoother and less chunky. It still just places buy orders though without following the rules correctly...
I'm having real problems trying to root out the cause of my codes failures.
I'm trying to simply create an ea that places a buy order if it is above three SMA (a 60 on the 5m, a 60 on the 1h, and 60 on the 4h), or places a sell order if it is below. This is not the full ea I'll be using, this is the starting process for a better plan. But I can't get past this first road block, as whenever I run my script it doesn't seem to take notice of my buy/sell conditions, and simply places buy orders throughout no matter where the current price is (above or below any of the SMA). It also never generates sell orders.
I hope I explained this correctly, and any help will be greatly appreciated!
Many thanks!
Cord
The code -
EDIT:
Ok, I have tried (I am very new to coding, started yesterday) to refine the code so it's smoother and less chunky. It still just places buy orders though without following the rules correctly...
//+------------------------------------------------------------------+
//| Trend system.mq4 |
//| Copyright © 2009, MetaQuotes Software Corp. |
//| Forex Trading Software: Forex Trading Platform MetaTrader 4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
extern double StopLoss = 150.0;
extern double TakeProfit = 300.0;
extern double LotSize = 0.01;
int start()
{
//----
int ticket;
int ready, sar, osc;
int sma, mma, lma; //---- Create the integers for the 3 SMA
for(int a=0;a<100;a++) //---- Loop
{
sma = iMA(NULL,0,60,0,MODE_SMA,PRICE_CLOSE,a); //---- Short sma, value of 60
mma = iMA(60,0,60,0,MODE_SMA,PRICE_CLOSE,a); //---- Medium sma, value of 720
lma = iMA(240,0,60,0,MODE_SMA,PRICE_CLOSE,a); //---- Long sma, value of 2880
ready = OrdersTotal();
if(Volume[0]==1) //---- assess current ticks
{
if(Close[1]>sma && Close[1]>mma && Close[1]>lma &&ready == 0) //---- establish if last candle closed above the three sma
{
ticket = OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,0,0,0,Green);
return(0);
}
else
if(Close[1]>sma && Close[1]>mma &&Close[1]<lma && ready ==0) //---- establish if last candle closed below the three sma
{
ticket = OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,0,0,0,Red);
return(0);
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+