|
|
| #property strict
|
| #property version "1.00"
|
| #property description "Kastakar Marathi Forex Algo - Demo Only"
|
|
|
| #include <Trade/Trade.mqh>
|
| CTrade trade;
|
|
|
| input double LotSize = 0.01;
|
| input int FastEMA = 9;
|
| input int SlowEMA = 21;
|
| input int StopLossPoints = 300;
|
| input int TakeProfitPoints = 450;
|
| input ulong MagicNumber = 20261120;
|
|
|
| int fastHandle;
|
| int slowHandle;
|
| datetime lastBarTime = 0;
|
|
|
| int OnInit()
|
| {
|
| trade.SetExpertMagicNumber(MagicNumber);
|
|
|
| fastHandle = iMA(_Symbol, PERIOD_M5, FastEMA,
|
| 0, MODE_EMA, PRICE_CLOSE);
|
|
|
| slowHandle = iMA(_Symbol, PERIOD_M5, SlowEMA,
|
| 0, MODE_EMA, PRICE_CLOSE);
|
|
|
| if(fastHandle == INVALID_HANDLE ||
|
| slowHandle == INVALID_HANDLE)
|
| return INIT_FAILED;
|
|
|
| return INIT_SUCCEEDED;
|
| }
|
|
|
| void OnTick()
|
| {
|
| datetime barTime = iTime(_Symbol, PERIOD_M5, 0);
|
|
|
| if(barTime == lastBarTime)
|
| return;
|
|
|
| lastBarTime = barTime;
|
|
|
| if(PositionSelect(_Symbol))
|
| return;
|
|
|
| double fast[2], slow[2];
|
|
|
| if(CopyBuffer(fastHandle, 0, 1, 2, fast) != 2)
|
| return;
|
|
|
| if(CopyBuffer(slowHandle, 0, 1, 2, slow) != 2)
|
| return;
|
|
|
| // BUY signal: EMA 9 crosses above EMA 21
|
| if(fast[0] <= slow[0] && fast[1] > slow[1])
|
| {
|
| double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
|
| double sl = ask - StopLossPoints * _Point;
|
| double tp = ask + TakeProfitPoints * _Point;
|
|
|
| trade.Buy(LotSize, _Symbol, 0, sl, tp,
|
| "Kastakar BUY");
|
| }
|
|
|
| // SELL signal: EMA 9 crosses below EMA 21
|
| if(fast[0] >= slow[0] && fast[1] < slow[1])
|
| {
|
| double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
|
| double sl = bid + StopLossPoints * _Point;
|
| double tp = bid - TakeProfitPoints * _Point;
|
|
|
| trade.Sell(LotSize, _Symbol, 0, sl, tp,
|
| "Kastakar SELL");
|
| }
|
| }
|
|
|
| void OnDeinit(const int reason)
|
| {
|
| IndicatorRelease(fastHandle);
|
| IndicatorRelease(slowHandle);
|
| } |