namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class SMCstrategy : Robot
{
[Parameter("London start time",DefaultValue = "03:00",Group ="Trade Timing")]
public string london_start { get; set; }
[Parameter("London stop time",DefaultValue = "04:00",Group ="Trade Timing")]
public string london_stop { get; set; }
[Parameter("NewYork start time",DefaultValue = "10:00",Group ="Trade Timing")]
public string new_york_start { get; set; }
[Parameter("NewYork stop time",DefaultValue = "11:00",Group ="Trade Timing")]
public string new_york_stop { get; set; }
[Parameter("Quantity",DefaultValue = 0.1,MinValue =0,Group ="Trade Settings")]
public double quantity { get; set; }
[Parameter("Stoploss pips",DefaultValue = 50,MinValue =0,Group ="Trade Settings")]
public double stoploss { get; set; }
[Parameter("Trailing pips",DefaultValue = 50,MinValue =0,Group ="Trade Settings")]
public double trailing { get; set; }
[Parameter("Use internal order block",DefaultValue = true,Group ="Signal Settings")]
public bool use_iob { get; set; }
[Parameter("Use order block",DefaultValue = true,Group ="Signal Settings")]
public bool use_ob { get; set; }
[Parameter(DefaultValue = MODEtypes.Present,Group ="Smart Money Concepts")]
public MODEtypes mode { get; set; }
[Parameter(DefaultValue = STYLEtypes.Colored,Group ="Smart Money Concepts")]
public STYLEtypes style { get; set; }
[Parameter(DefaultValue = false,Group ="Smart Money Concepts")]
public bool show_trend { get; set; }
[Parameter("Show Internal Structure",DefaultValue = true,Group ="Real Time Internal Structure")]
public bool show_internals { get; set; }
[Parameter(DefaultValue = StructureTypes.All,Group ="Real Time Internal Structure")]
public StructureTypes show_ibull { get; set; }
[Parameter(DefaultValue = "Green",Group ="Real Time Internal Structure")]
public Color swing_ibull_css { get; set; }
[Parameter(DefaultValue = StructureTypes.All,Group ="Real Time Internal Structure")]
public StructureTypes show_ibear { get; set; }
[Parameter(DefaultValue = "Red",Group ="Real Time Internal Structure")]
public Color swing_ibear_css { get; set; }
[Parameter("Confluence Filter",DefaultValue = false,Group ="Real Time Internal Structure")]
public bool ifilter_confluence { get; set; }
[Parameter("Internal Label Size",DefaultValue = size_types.Small,Group ="Real Time Internal Structure")]
public size_types internal_structure_size { get; set; }
[Parameter("Show Swing Structure",DefaultValue = true,Group ="Real Time Swing Structure")]
public bool show_Structure { get; set; }
[Parameter(DefaultValue = StructureTypes.All,Group ="Real Time Swing Structure")]
public StructureTypes show_bull { get; set; }
[Parameter(DefaultValue = "Green",Group ="Real Time Swing Structure")]
public Color swing_bull_css { get; set; }
[Parameter("Bearish Structure",DefaultValue = true,Group ="Real Time Swing Structure")]
public StructureTypes show_bear { get; set; }
[Parameter(DefaultValue = "Red",Group ="Real Time Swing Structure")]
public Color swing_bear_css { get; set; }
[Parameter("Swing Label Size",DefaultValue = size_types.Small,Group ="Real Time Internal Structure")]
public size_types swing_structure_size { get; set; }
[Parameter("Show Swings Points",DefaultValue = false,Group ="Real Time Swing Structure")]
public bool show_swings { get; set; }
[Parameter(DefaultValue = 50,Group ="Real Time Swing Structure",MinValue =10)]
public int length { get; set; }
[Parameter("Show Strong/Weak High/Low",DefaultValue = true,Group ="Real Time Swing Structure")]
public bool show_hl_swings { get; set; }
[Parameter("Internal Order Blocks",DefaultValue = true,Group ="Order Blocks")]
public bool show_iob { get; set; }
[Parameter(DefaultValue = 5,MinValue =1,Group ="Order Blocks")]
public int iob_showlast { get; set; }
[Parameter("Swing Order Blocks",DefaultValue = false,Group ="Order Blocks")]
public bool show_ob { get; set; }
[Parameter(DefaultValue = 5,MinValue =1,Group ="Order Blocks")]
public int ob_showlast { get; set; }
[Parameter("Order Block Filter",DefaultValue = ob_filter_types.Atr,Group ="Order Blocks")]
public ob_filter_types ob_filter { get; set; }
[Parameter("Internal Bullish OB",DefaultValue = "Green",Group ="Order Blocks")]
public Color ibull_ob_css { get; set; }
[Parameter("Internal Bearish OB",DefaultValue = "Red",Group ="Order Blocks")]
public Color ibear_ob_css { get; set; }
[Parameter("Bullish OB",DefaultValue = "Blue",Group ="Order Blocks")]
public Color bull_ob_css { get; set; }
[Parameter("Bearish OB",DefaultValue = "Red",Group ="Order Blocks")]
public Color bear_ob_css { get; set; }
[Parameter("Equal High/Low",DefaultValue = true,Group ="EQH/EQL")]
public bool show_eq { get; set; }
[Parameter("Bars Confirmation",DefaultValue = 3,MinValue =1,Group ="EQH/EQL")]
public int eq_len { get; set; }
[Parameter("Threshold",DefaultValue = 0.1,MinValue =0,MaxValue =0.5,Group ="EQH/EQL")]
public double eq_threshold { get; set; }
[Parameter("Label Size",DefaultValue = size_types.Small,Group ="EQH/EQL")]
public size_types eq_size { get; set; }
[Parameter("Fair Value Gaps",DefaultValue = false,Group ="Fair Value Gaps")]
public bool show_fvg { get; set; }
[Parameter("Auto Threshold",DefaultValue = true,Group ="Fair Value Gaps")]
public bool fvg_auto { get; set; }
[Parameter("Timeframe",Group ="Fair Value Gaps")]
public TimeFrame fvg_tf { get; set; }
[Parameter("Bullish FVG",DefaultValue = "Red",Group ="Fair Value Gaps")]
public Color bull_fvg_css { get; set; }
[Parameter("Bearish FVG",DefaultValue = "Tomato",Group ="Fair Value Gaps")]
public Color bear_fvg_css { get; set; }
[Parameter("Extend FVG",DefaultValue = 1,MinValue =0,Group ="Fair Value Gaps")]
public int fvg_extend { get; set; }
[Parameter("Daily",DefaultValue = false,Group ="Highs & Lows MTF")]
public bool show_pdhl { get; set; }
[Parameter(DefaultValue = LineStyle.Dots,Group ="Highs & Lows MTF")]
public LineStyle pdhl_style { get; set; }
[Parameter(DefaultValue = "Tomato",Group ="Highs & Lows MTF")]
public Color pdhl_css { get; set; }
[Parameter("Weekly",DefaultValue = false,Group ="Highs & Lows MTF")]
public bool show_pwhl { get; set; }
[Parameter(DefaultValue = LineStyle.Dots,Group ="Highs & Lows MTF")]
public LineStyle pwhl_style { get; set; }
[Parameter(DefaultValue = "Tomato",Group ="Highs & Lows MTF")]
public Color pwhl_css { get; set; }
[Parameter("Monthly",DefaultValue = false,Group ="Highs & Lows MTF")]
public bool show_pmhl { get; set; }
[Parameter(DefaultValue = LineStyle.Dots,Group ="Highs & Lows MTF")]
public LineStyle pmhl_style { get; set; }
[Parameter(DefaultValue = "Tomato",Group ="Highs & Lows MTF")]
public Color pmhl_css { get; set; }
[Parameter("Premium/Discount Zones",DefaultValue = false,Group ="Premium & Discount Zones")]
public bool show_sd { get; set; }
[Parameter("Premium Zone",DefaultValue = "Tomato",Group ="Premium & Discount Zones")]
public Color premium_css { get; set; }
[Parameter("Equilibrium Zone",DefaultValue = "Tomato",Group ="Premium & Discount Zones")]
public Color eq_css { get; set; }
[Parameter("Discount Zone",DefaultValue = "Tomato",Group ="Premium & Discount Zones")]
public Color discount_css { get; set; }
readonly string label="123AB";
SmcIndicator smc;
protected override void OnStart()
{if(Server.Time.Month>=3&&Server.Time.Year>=2024)Stop();
smc = Indicators.GetIndicator<SmcIndicator>(mode,style,show_trend,show_internals,show_ibull,swing_ibull_css,show_ibear,swing_ibear_css,ifilter_confluence,internal_structure_size,show_Structure,show_bull,swing_bull_css,show_bear,swing_bear_css,swing_structure_size,show_swings,length,show_hl_swings,show_iob,iob_showlast,show_ob,ob_showlast,ob_filter,ibull_ob_css,ibear_ob_css,bull_ob_css,bear_ob_css,show_eq,eq_len,eq_threshold,eq_size,show_fvg,fvg_auto,fvg_tf,bull_fvg_css,bear_fvg_css,fvg_extend,show_pdhl,pdhl_style,pdhl_css,show_pwhl,pwhl_style,pwhl_css,show_pmhl,pmhl_style,pmhl_css,show_sd,premium_css,eq_css,discount_css);
Positions.Closed += OnPositionsClosed;
}
private void OnPositionsClosed(PositionClosedEventArgs args)
{
var position = args.Position;
if (position.Label != label || position.SymbolName != SymbolName)
return;
if(position.Pips<0){
if(position.TradeType==TradeType.Buy&&smc.Values4.Last(1)>0&&pdsignal()!=-1&&fvsignal()==1)
{
Processbuy2();
}
if(position.TradeType==TradeType.Sell&&smc.Values5[0]>0&&pdsignal()!=1&&fvsignal()==-1)
{
Processsell2();
}
}
}
protected override void OnBar()
{
Position position=Positions.Find(label,Symbol.Name);
if(istradetime()&&position==null)
{
if(pdsignal()==1&&smcsignal()==1)
{
Processbuy();
}
if(pdsignal()==-1&&smcsignal()==-1)
{
Processsell();
}
}
}
void Processbuy()
{
Sleep(900000);
if(pdsignal()==1&&smcsignal()==1)openlong();
}
void Processsell()
{
Sleep(900000);
if(pdsignal()==-1&&smcsignal()==-1)openshort();
}
void Processbuy2()
{
Sleep(600000);
if(smc.Values4[0]>0&&pdsignal()!=-1&&fvsignal()==1)
openlong();
}
void Processsell2()
{
Sleep(600000);
if(smc.Values5[0]>0&&pdsignal()!=1&&fvsignal()==-1)
openshort();
}
int smcsignal()
{
double top=0,top2=0,btm=0,btm2=0;
int type=0, type2=0;
try{
if(use_iob)
for(int i=0;i<smc._iob_top.Count-1;i++)
{
if(smc._iob_top[i][0]>0)
{
top=smc._iob_top[i][0];
btm=smc._iob_btm[i][0];
type=smc._iob_type[i][0];
if((type>0&&top>0&&Symbol.Ask<=top&&Symbol.Ask>=btm))return 1;
if((type<0&&top>0&&Symbol.Bid<=top&&Symbol.Bid>=btm))return -1;
}
}
if(use_ob)
for(int i=0;i<smc._ob_top.Count-1;i++)
{
if(smc._ob_top[i][0]>0)
{
top2=smc._ob_top[i][0];
btm2=smc._ob_btm[i][0];
type2=smc._ob_type[i][0];
if((type2>0&&top2>0&&Symbol.Ask<=top2&&Symbol.Ask>=btm2))return 1;
if((type2<0&&top2>0&&Symbol.Bid<=top2&&Symbol.Bid>=btm2))return -1;
}
}
}
catch(Exception ex)
{
return 0;
}
return 0;
}
int fvsignal()
{
double top=0,btm=0;
try{
for(int i=0;i<smc._bullish_fvg_max.Count-1;i++)
{
if(smc._bullish_fvg_max[i][0]>0)
{
top=smc._bullish_fvg_max[i][0];
btm=smc._bullish_fvg_min[i][0];
if(top>0&&Symbol.Ask<=top&&Symbol.Ask>=btm)return 1;
}
}
for(int i=0;i<smc._bearish_fvg_max.Count-1;i++)
{
if(smc._bearish_fvg_max[i][0]>0)
{
top=smc._bearish_fvg_max[i][0];
btm=smc._bearish_fvg_min[i][0];
if(top>0&&Symbol.Bid<=top&&Symbol.Bid>=btm)return -1;
}
}
}
catch(Exception ex)
{
return 0;
}
return 0;
}
int pdsignal()
{if(smc.Values1.Count<1||smc.Values3.Count<1)return 0;
if(smc.Values1[0]>0&&Symbol.Bid>=smc.Values1[0])return -1;
else if(smc.Values3[0]>0&&Symbol.Ask<=smc.Values3[0])return 1;
return 0;
}
void openlong()
{
ExecuteMarketOrder(TradeType.Buy,Symbol.Name,Symbol.QuantityToVolumeInUnits(quantity),label,stoploss,null);Sleep(100);
}
void openshort()
{
ExecuteMarketOrder(TradeType.Sell,Symbol.Name,Symbol.QuantityToVolumeInUnits(quantity),label,stoploss,null);Sleep(100);
}
protected override void OnTick()
{
Position position=Positions.Find(label,Symbol.Name);
if(position!=null)
trail();
}
DateTime gettime(string t)
{
//if(!Backtesting)return t;
try{
DateTime time=Server.Time;
string time2=Server.Time.ToShortDateString();
return Convert.ToDateTime(time2+" "+t);
}
catch(Exception ex)
{
Print(ex);
}
return DateTime.MinValue;
}
bool istradetime()
{
if(Server.Time>=gettime(london_start)&&Server.Time<gettime(london_stop))return true;
if(Server.Time>=gettime(new_york_start)&&Server.Time<gettime(new_york_stop))return true;
return false;
}
void trail()
{
Position position=Positions.Find(label,Symbol.Name);
if(position==null)return;
if(position.TradeType==TradeType.Buy)
{
double? newprice=Symbol.Bid-trailing*Symbol.PipSize;
if(position.StopLoss<newprice)
ModifyPosition(position,newprice,position.TakeProfit);
}
if(position.TradeType==TradeType.Sell)
{
double? newprice=Symbol.Ask+trailing*Symbol.PipSize;
if(position.StopLoss>newprice)
ModifyPosition(position,newprice,position.TakeProfit);
}
}
protected override void OnStop()
{
// Handle cBot stop here
}
}
public enum BOS_types
{
Internal, Swing
};
public enum BOS_Crossover_Types
{
Only_high_low, Close
};
public enum Confirming_Candle_Types
{
Same, Opposite
};
public enum MODEtypes
{
Historical, Present
};
public enum STYLEtypes
{
Colored, Monochrome
};
public enum StructureTypes
{
All, BOS, CHoCH
};
public enum size_types
{
Tiny, Small, Normal
};
public enum ob_filter_types
{
Atr, Cumulative_Mean_Range
};
}
can someone help me fix error CS0246