COULD ANYONE HELP ME TO CODE A SIMPLE EA?

 

I need an EA that opens a trade when candle reaches certain pips. thats it.

variables: pips to trigger

Sl

Tp

lots

Magic number.




Thanks

 
csbueno wrote >>

I need an EA that opens a trade when candle reaches certain pips. thats it.

variables: pips to trigger

Sl

Tp

lots

Magic number.

Thanks

I did something like this last year. This is what I came up with:

//+------------------------------------------------------------------+
//| Daily Distance 1 minute chart |
//| May 08 |
//| |
//+------------------------------------------------------------------+


extern int StopLoss = 50;
extern int TakeProfit = 100;
extern int Trigger = 25;
extern int MagicNumber = 0;
extern int StartTime = 8;
extern int EndTime = 20;
extern double PercentRisked = 2;
extern int Slippage = 3;
int TradeDay;
int TradeHour;
int TradeMinute;
string direction;

//+------------------------------------------------------------------+
//| Calculate open positions |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
//---- return orders volume
if(buys>0) return(buys);
else return(-sells);
}

//+------------------------------------------------------------------+
//| Check for Open |
//+------------------------------------------------------------------+
void CheckForOpen()
{

//+------------------------------------------------------------------+
//| Set Lots to 2% of total Balance |
//+------------------------------------------------------------------+
double PercentRisked = 2;
double AveragePrice = (Bid + (Ask-Bid)/2);
double RiskPercent = PercentRisked / 100;
double DollarsPerLot,Lots,BigLots ;
if ((Symbol() == "AUDUSD") || (Symbol() == "EURUSD") || (Symbol() == "GBPUSD") || (Symbol() == "NZDUSD"))
{
DollarsPerLot = 10;
Lots = NormalizeDouble(((AccountBalance()* RiskPercent)/(StopLoss*0.1)/DollarsPerLot),2);
}
else
if (Symbol() == "USDJPY")
{
DollarsPerLot = (100/AveragePrice*10);
Lots = NormalizeDouble(((AccountBalance()* RiskPercent)/(StopLoss*0.1)/DollarsPerLot),2);
}
else
if (Symbol() == "USDCAD" || (Symbol() == "USDCHF"))
{
DollarsPerLot = (1/AveragePrice*10);
Lots = NormalizeDouble(((AccountBalance()* RiskPercent)/(StopLoss*0.1)/DollarsPerLot),2);
}
else
{
DollarsPerLot = 10;
Lots = NormalizeDouble(((AccountBalance()* RiskPercent)/(StopLoss*0.1)/DollarsPerLot)/2,2);
}

//--- set trade variables
int res;
double CurrentBuy=Ask;
double CurrentSell=Bid;
double PeriodOpen = iOpen(NULL,PERIOD_M1,0);
double DistanceBuy = PeriodOpen + Trigger*Point;
double DistanceSell = PeriodOpen - Trigger*Point;
int Time_Day = TimeDay(TimeCurrent());
int Time_Hour = TimeHour(TimeCurrent());
int Time_Minute = TimeMinute(TimeCurrent());
double StopLossBuy = Ask-StopLoss*Point;
double StopLossSell = Bid+StopLoss*Point;
double TakeProfitBuy = Ask+TakeProfit*Point;
double TakeProfitSell = Bid-TakeProfit*Point;

if (TradeDay == Time_Day && TradeHour == Time_Hour && TradeMinute == Time_Minute)
return;

//--- Buy - limit to one trade per direction per minute
if(CurrentBuy >= DistanceBuy)
{

res=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,StopLossBuy,TakeProfitBuy,"Buy(#" + MagicNumber + ")",MagicNumber,0,DodgerBlue);
Print("Trigger "+Trigger+" PeriodOpen "+PeriodOpen+" CurrentBuy "+CurrentBuy+" DistanceBuy "+DistanceBuy+" Ask "+Ask+" TakeProfitBuy "+TakeProfitBuy+ " StopLossBuy "+StopLossBuy);
TradeDay = Time_Day;
TradeHour = Time_Hour;
TradeMinute = Time_Minute;

return;
}
//--- Sell - limit to one trade per direction per minute
if(CurrentSell <= DistanceSell)
{

res=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,StopLossSell,TakeProfitSell,"Sell(#" + MagicNumber + ")",MagicNumber,0,DodgerBlue);
Print("Trigger "+Trigger+" PeriodOpen "+PeriodOpen+" CurrentSell "+CurrentSell+" DistanceSell "+DistanceSell+" Bid "+Bid+" TakeProfitSell "+TakeProfitSell+ " StopLossSell "+StopLossSell);
TradeDay = Time_Day;
TradeHour = Time_Hour;
TradeMinute = Time_Minute;

return;
}
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void start()
{
//---- Only Trade During Active Hours
if ((TimeHour(TimeCurrent()) < StartTime) || (TimeHour(TimeCurrent()) > EndTime)) return;
if(CalculateCurrentOrders(Symbol())==0)
{
CheckForOpen();
}
// else CheckForClose();
//----
}
//+------------------------------------------------------------------+

 
joetrader:

I did something like this last year. This is what I came up with:




Thanks a lot


Regards

Carlos

Reason: