Various-Expert-Ideas/1Min-930EST-FVG-Scalper.mq5

165 lines
6.5 KiB
MQL5

//+------------------------------------------------------------------+
//| 1Min-Scalper.mq5 |
//| Bahram Dolati 2025 |
//| bahram.dolati2@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Bahram Dolati 2025"
#property link "bahram.dolati2@gmail.com"
#property version "1.00"
#property description "This Expert is a Scalping Strategy and Only works in 1 Min"
#property description "This code is an Expert to test Casper SMC's scalping video on Youtube Titled:"
#property description "This Scalping Strategy Works Everyday (Stupid Simple And Proven)"
#property description "Link: https://youtu.be/mzFXoK2pbNE"
#property description "Because my borkers timezone in +2:00GMT, the 9:30EST would be 16:30 in Metatrader."
#include <Trade/Trade.mqh>
#include <Trade/PositionInfo.mqh>
#include <EAFunctions.mqh>
CPositionInfo PositionInfo;
CTrade trade;
input group "=== Risk Management ==="
input double InpTradeVolume = 0.01; //Trade Volume
input int InpMagicNumber = 2025007;
input string InpTradeComment = "FVG for 9:30 EST";
input int InpNoActivePositions = 1;
enum direction {
LongBreak,
ShortBreak,
UnKnown,
};
struct FMZone {
double high;
double low;
bool traded;
direction dir;
double SL;
}; //Five Min Zone
int OnInit()
{
IsNewBar(_Symbol, _Period, true);
if(_Period != PERIOD_M1){
Print("Wrong timeframe !!! This EA only works in 1M !!!!!!");
return(INIT_FAILED);
}
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
if(!IsNewBar(_Symbol, _Period, true)) return;
double close[], low[],high[], open[], tp,sl;
string rect="Rect Zone";
static FMZone Candle_1635_Struct;
double spread = MathAbs( SymbolInfoDouble(_Symbol, SYMBOL_BID) - SymbolInfoDouble(_Symbol, SYMBOL_ASK)), price;
//initializing struct
// Candle_1635_Struct.high = 0.0e0;
// Candle_1635_Struct.low = 0.0e0;
// Candle_1635_Struct.traded = true;
// Candle_1635_Struct.dir = UnKnown;
// Candle_1635_Struct.SL = 0.0e0;
datetime Candle_1635_Time;
MqlDateTime Candle_1635_Time_Struct;
//fiding high and low of candle 16:30 in 5N using current tf which is 1M
Candle_1635_Time = iTime(_Symbol, PERIOD_CURRENT, 1);
TimeToStruct(Candle_1635_Time, Candle_1635_Time_Struct);
if( Candle_1635_Time_Struct.hour ==16 && Candle_1635_Time_Struct.min == 34 ){
Candle_1635_Struct.high = iHigh(_Symbol, PERIOD_CURRENT, iHighest(_Symbol, PERIOD_CURRENT, MODE_HIGH, 5,1));
Candle_1635_Struct.low = iLow(_Symbol, PERIOD_CURRENT, iLowest(_Symbol, PERIOD_CURRENT, MODE_LOW, 5,1));
if(!ObjectCreate(0, "rect"+TimeToString(TimeCurrent(), TIME_DATE ), OBJ_RECTANGLE, 0, iTime(_Symbol, PERIOD_CURRENT, 5), Candle_1635_Struct.low, iTime(_Symbol, PERIOD_CURRENT, 1),Candle_1635_Struct.high)){
Print("Rectangle Creation failed");
}
Candle_1635_Struct.traded = false;
Candle_1635_Struct.dir = UnKnown;
Candle_1635_Struct.SL = 0.0e0;
Print("High: ",Candle_1635_Struct.high, " Low: ", Candle_1635_Struct.low," ", TimeToString(TimeCurrent()) );
//Continue saving Highest and Lowest/
}
//Print("High: ",Candle_1635_Struct.high, " Low: ", Candle_1635_Struct.low," ", TimeToString(TimeCurrent()) );
//finding direction and SL
ArraySetAsSeries(close, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(open, true);
CopyClose(_Symbol, PERIOD_CURRENT, 1, 5, close);
CopyLow(_Symbol, PERIOD_CURRENT, 1,5, low);
CopyHigh(_Symbol, PERIOD_CURRENT, 1,5, high);
CopyOpen(_Symbol,PERIOD_CURRENT, 1, 5, open);
//Print(close[1], " iClose1: ", iClose(_Symbol, PERIOD_CURRENT, 1)," ", close[4], " iClose4: ", iClose(_Symbol, PERIOD_CURRENT, 4));
// Print("1: ",close[0]," 2: ",close[1]," 3: ",close[2]," 4: ",close[3], " 5: ", close[4]);
if(close[0] > Candle_1635_Struct.high && open[0] < Candle_1635_Struct.high && open[0] > Candle_1635_Struct.low && Candle_1635_Struct.dir == UnKnown ){
Candle_1635_Struct.dir = LongBreak;
Candle_1635_Struct.SL = low[0];
Candle_1635_Struct.traded = false;
Print("Long Break Happened: ", Candle_1635_Struct.dir, " Sl: ", Candle_1635_Struct.SL, "traded: ", Candle_1635_Struct.traded);
if( !ObjectCreate(0, TimeToString(TimeCurrent())+DoubleToString(low[0]),OBJ_ARROW_THUMB_UP,0, iTime(_Symbol, PERIOD_CURRENT, 1), low[0])){
Print(GetLastError());
}
}
else if( close[0] < Candle_1635_Struct.low && open[0] > Candle_1635_Struct.low && open[0] < Candle_1635_Struct.high && Candle_1635_Struct.dir ==UnKnown ){
Candle_1635_Struct.dir = ShortBreak;
Candle_1635_Struct.SL = high[0];
Print("Short Break Happened: ", Candle_1635_Struct.dir, " Sl: ", Candle_1635_Struct.SL);
if( !ObjectCreate(0, TimeToString(TimeCurrent())+DoubleToString(high[0]),OBJ_ARROW_THUMB_DOWN,0, iTime(_Symbol, PERIOD_CURRENT, 1), high[0])){
Print(GetLastError());
}
}
if( close[0]> Candle_1635_Struct.high && close[1] > Candle_1635_Struct.high
&& low[0] > low[2] //FVG marker for Bullish
&& Candle_1635_Struct.dir == LongBreak && !Candle_1635_Struct.traded
&& NumberOfActivePositions(_Symbol, InpTradeComment, InpMagicNumber, POSITION_TYPE_BUY, false) < InpNoActivePositions
){
price = SymbolInfoDouble(_Symbol, SYMBOL_BID);
sl = Candle_1635_Struct.SL -spread;
tp = price + MathAbs(price - sl)*2.0e0 - spread;
trade.Buy(InpTradeVolume, _Symbol, price, sl, tp, InpTradeComment);
Candle_1635_Struct.traded = true;
}
else if( close[0] < Candle_1635_Struct.low && close[1] < Candle_1635_Struct.low
&& high[0] < high[2] //FVG marker for bearish
&& Candle_1635_Struct.dir == ShortBreak && !Candle_1635_Struct.traded
&& NumberOfActivePositions(_Symbol, InpTradeComment, InpMagicNumber, POSITION_TYPE_SELL, false) < InpNoActivePositions
){
price = price = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
sl = Candle_1635_Struct.SL + spread;
tp = price - MathAbs(price - sl)*2.0e0 + spread;
trade.Sell(InpTradeVolume, _Symbol, price, sl, tp, InpTradeComment);
Candle_1635_Struct.traded = true;
}
}
double OnTester()
{
double ret=0.0;
return(ret);
}