Code: Select all
int OnInit()
{
//----
//Zoom the chart out as soon as possible. I do this at the start
//of GetSixths() as well - does no harm.
int scale = ChartScaleGet();
if (scale != 0)
{
ChartScaleSet(0);
//A quick time frame change to force accurate display
per = ChartPeriod(0);
int nextPer = GetNextPeriod(per);
ChartSetSymbolPeriod(0, Symbol(), nextPer);//Change time frame
ChartSetSymbolPeriod(0, Symbol(), per);//reset time frame
}//if (scale != 0)
if (UseChandelierExit)
if (!indiExists( "chandelier-exit" ))
{
Alert("");
Alert("Download the indi from the Dottybot thread");
Alert("The required indicator 'chandelier-exit' does not exist on your platform. I am removing myself from your chart.");
RemoveExpert = true;
ExpertRemove();
return(0);
}//if (! indiExists( "IndiName" ))
//Adapt this to suit the indi you are using
/*if (!indiExists( HGI_Name ))
{
Alert("");
Alert("Download the indi from Bob's HGI thread and adit the HGI_Name input");
Alert("The required indicator ", HGI_Name, " does not exist on your platform. I am removing myself from your chart.");
RemoveExpert = true;
ExpertRemove();
return(0);
}//if (! indiExists( "IndiName" ))
*/
//~ Set up the pips factor. tp and sl etc.
//~ The EA uses doubles and assume the value of the integer user inputs. This:
//~ 1) minimises the danger of the inputs becoming corrupted by restarts;
//~ 2) the integer inputs cannot be divided by factor - doing so results in zero.
factor = GetPipFactor(Symbol());
StopLoss = StopLossPips;
TakeProfit = TakeProfitPips;
BreakEvenPips = BreakEvenTargetPips;
BreakEvenProfit = BreakEvenTargetProfit;
JumpingStopPips = JumpingStopTargetPips;
TrailingStopPips = TrailingStopTargetPips;
HiddenPips = PipsHiddenFromCriminal;
BasketTakeProfit = BasketTakeProfitPips;
//Adjust the right side margin
double mar = ChartShiftSizeGet(0);
if (!CloseEnough(mar, 10))
ChartShiftSizeSet(10, 0);
if (DistanceBetweenTradesPips > 0)
DistanceBetweenTrades = DistanceBetweenTradesPips;
else
ReadIndicatorValues();
while (IsConnected()==false)
{
Comment("Waiting for Empty4 connection...");
Sleep(1000);
}//while (IsConnected()==false)
//MaxTradesAllowed needs to be 1 if we are using the grid and
//ImmediateMarketOrders is enabled to avoid sending a new trade
//on every new signal.
if (UseGrid)
MaxTradesAllowed = 1;
//Lot size and part-close idiot check for the cretins. Code provided by phil_trade. Many thanks, Philippe.
//adjust Min_lot
if (CloseEnough(RiskPercent, 0) )
if(Lot<MarketInfo(Symbol(),MODE_MINLOT))
{
Alert(Symbol()+" Lot was adjusted to Minlot = "+DoubleToStr(MarketInfo(Symbol(),MODE_MINLOT),Digits));
Lot=MarketInfo(Symbol(),MODE_MINLOT);
}//if (Lot < MarketInfo(Symbol(), MODE_MINLOT))
/*
//check Partial close parameters
if (PartCloseEnabled == true)
{
if (Lot < Close_Lots + Preserve_Lots || Lot < MarketInfo(Symbol(), MODE_MINLOT) + Close_Lots )
{
Alert(Symbol()+" PartCloseEnabled is disabled because Lot < Close_Lots + Preserve_Lots or Lot < MarketInfo(Symbol(), MODE_MINLOT) + Close_Lots !");
PartCloseEnabled = false;
}//if (Lot < Close_Lots + Preserve_Lots || Lot < MarketInfo(Symbol(), MODE_MINLOT) + Close_Lots )
}//if (PartCloseEnabled == true)
*/
//Jumping/trailing stops need breakeven set before they work properly
if ((JumpingStop || TrailingStop) && !BreakEven)
{
BreakEven = true;
if (JumpingStop) BreakEvenPips = JumpingStopPips;
if (TrailingStop) BreakEvenPips = TrailingStopPips;
}//if (JumpingStop || TrailingStop)
Gap="";
if (DisplayGapSize >0)
{
for (int cc=0; cc< DisplayGapSize; cc++)
{
Gap = StringConcatenate(Gap, " ");
}
}//if (DisplayGapSize >0)
//Reset CriminIsECN if crim is Cowboy IBFX and the punter does not know or, like me, keeps on forgetting
string name = TerminalCompany();
int ispart = StringFind(name, "Cowboy IBFX", 0);
if (ispart < 0) ispart = StringFind(name, "Interbank FX", 0);
if (ispart > -1) IsGlobalPrimeOrECNCriminal = true;
ispart = StringFind(name, "Global Prime", 0);
if (ispart > -1) IsGlobalPrimeOrECNCriminal = true;
//Set up the trading hours
tradingHoursDisplay = tradingHours;//For display
initTradingHours();//Sets up the trading hours array
// Initialize libCSS
if (UseCSS) libCSSinit();
if (TradeComment == "") TradeComment = " ";
OldBars = Bars;
TicketNo = -1;
if (DistanceBetweenTradesPips == 0)//RIV is called higher up if DistanceBetweenTradesPips > 0
ReadIndicatorValues();//For initial display in case user has turned of constant re-display
GetSwap(Symbol());//This will need editing/removing in a multi-pair ea.
TradeDirectionBySwap();
TooClose();
CountOpenTrades();
OldOpenTrades = OpenTrades;
TradeTimeOk = CheckTradingTimes();
if (!IsTesting() )
{
//Changed by tomele
//The spread global variable
SpreadGvName = Symbol() + " average spread";
AverageSpread = GlobalVariableGet(SpreadGvName);//If no gv, then the value will be left at zero.
}//if (!IsTesting() )
//Chart display
if (DisplayAsText)
if (KeepTextOnTop)
ChartForegroundSet(false,0);// change chart to background
//Ensure that an ea depending on Close[1] for its values does not immediately fire a trade.
if (!EveryTickMode) OldBarsTime = iTime(Symbol(), TradingTimeFrame, 0);
//Lot size based on account size
if (!CloseEnough(LotsPerDollopOfCash, 0))
CalculateLotAsAmountPerCashDollops();
//Time frame display
TradingTimeFrameDisplay = GetTimeFrameDisplay(TradingTimeFrame);
TrendTimeFrameDisplay = GetTimeFrameDisplay(TrendTimeFrame);
//Detect the previous trend
TrendGvName = "HGBnD " + Symbol() + " trend ";
if(!GlobalVariableCheck(TrendGvName) )
{
GlobalVariableSet(TrendGvName, notrend);
}//if(!GlobalVariableCheck(TrendGvName) )
OldLongTrendDetected = false;
OldShortTrendDetected = false;
int t = GlobalVariableGet(TrendGvName);
if (t == longtrend)
OldLongTrendDetected = true;
if (t == shorttrend)
OldShortTrendDetected = true;
DisplayUserFeedback();
//Create the labels
string tfDisplay = "";
DisplayCount = 1;
if (UseBuyLowSellHigh)
{
if (UseHighestTimeFrame)
{
if (ObjectFind(highestTimeFrameLabelName) < 0)
{
ObjectCreate(highestTimeFrameLabelName, OBJ_LABEL, 0, 0, 0);
ObjectSet(highestTimeFrameLabelName, OBJPROP_CORNER, 0);
//ObjectSet(highestTimeFrameLabelName, OBJPROP_XDISTANCE, BlshDisplayX + ofset);
ObjectSet(highestTimeFrameLabelName, OBJPROP_XDISTANCE, BlshDisplayX);
ObjectSet(highestTimeFrameLabelName, OBJPROP_YDISTANCE, BlshDisplayY+DisplayCount*(BlshfontSise+4));
ObjectSet(highestTimeFrameLabelName, OBJPROP_BACK, false);
tfDisplay = GetTimeFrameDisplay(HighestTimeFrame);
ObjectSetText(highestTimeFrameLabelName, tfDisplay, BlshfontSise, BlshfontName, HighestTimeFrameLineColour);
}//if (ObjectFind(highestTimeFrameLabelName) < 0)
if (ObjectFind(highestTimeFrameLabelDirection) < 0)
{
ObjectCreate(highestTimeFrameLabelDirection, OBJ_LABEL, 0, 0, 0);
ObjectSet(highestTimeFrameLabelDirection, OBJPROP_CORNER, 0);
ObjectSet(highestTimeFrameLabelDirection, OBJPROP_XDISTANCE, BlshDisplayX + 50);
ObjectSet(highestTimeFrameLabelDirection, OBJPROP_YDISTANCE, BlshDisplayY+DisplayCount*(BlshfontSise+4));
ObjectSet(highestTimeFrameLabelDirection, OBJPROP_BACK, false);
ObjectSetText(highestTimeFrameLabelDirection, highestBlshStatus, BlshfontSise, BlshfontName, BuyColour);
}//if (ObjectFind(highestTimeFrameLabelDirection) < 0)
DisplayCount++;
}//if (UseHighestTimeFrame)
if (UseHighTimeFrame)
{
if (ObjectFind(highTimeFrameLabelName) < 0)
{
ObjectCreate(highTimeFrameLabelName, OBJ_LABEL, 0, 0, 0);
ObjectSet(highTimeFrameLabelName, OBJPROP_CORNER, 0);
//ObjectSet(highTimeFrameLabelName, OBJPROP_XDISTANCE, BlshDisplayX + ofset);
ObjectSet(highTimeFrameLabelName, OBJPROP_XDISTANCE, BlshDisplayX);
ObjectSet(highTimeFrameLabelName, OBJPROP_YDISTANCE, BlshDisplayY+DisplayCount*(BlshfontSise+10));
ObjectSet(highTimeFrameLabelName, OBJPROP_BACK, false);
tfDisplay = GetTimeFrameDisplay(HighTimeFrame);
ObjectSetText(highTimeFrameLabelName, tfDisplay, BlshfontSise, BlshfontName, HighTimeFrameLineColour);
}//if (ObjectFind(highTimeFrameLabelName) < 0)
if (ObjectFind(highTimeFrameLabelDirection) < 0)
{
ObjectCreate(highTimeFrameLabelDirection, OBJ_LABEL, 0, 0, 0);
ObjectSet(highTimeFrameLabelDirection, OBJPROP_CORNER, 0);
//ObjectSet(highTimeFrameLabelDirection, OBJPROP_XDISTANCE, BlshDisplayX + ofset);
ObjectSet(highTimeFrameLabelDirection, OBJPROP_XDISTANCE, BlshDisplayX + 50);
ObjectSet(highTimeFrameLabelDirection, OBJPROP_YDISTANCE, BlshDisplayY+DisplayCount*(BlshfontSise+10));
ObjectSet(highTimeFrameLabelDirection, OBJPROP_BACK, false);
ObjectSetText(highTimeFrameLabelDirection, highBlshStatus, BlshfontSise, BlshfontName, BuyColour);
}//if (ObjectFind(highestTimeFrameLabelDirection) < 0)
DisplayCount++;
}//if (UseHighTimeFrame)
if (UseMediumTimeFrame)
{
if (ObjectFind(mediumTimeFrameLabelName) < 0)
{
ObjectCreate(mediumTimeFrameLabelName, OBJ_LABEL, 0, 0, 0);
ObjectSet(mediumTimeFrameLabelName, OBJPROP_CORNER, 0);
//ObjectSet(mediumTimeFrameLabelName, OBJPROP_XDISTANCE, BlshDisplayX + ofset);
ObjectSet(mediumTimeFrameLabelName, OBJPROP_XDISTANCE, BlshDisplayX);
ObjectSet(mediumTimeFrameLabelName, OBJPROP_YDISTANCE, BlshDisplayY+DisplayCount*(BlshfontSise+10));
ObjectSet(mediumTimeFrameLabelName, OBJPROP_BACK, false);
tfDisplay = GetTimeFrameDisplay(MediumTimeFrame);
ObjectSetText(mediumTimeFrameLabelName, tfDisplay, BlshfontSise, BlshfontName, MediumTimeFrameLineColour);
}//if (ObjectFind(mediumTimeFrameLabelName) < 0)
if (ObjectFind(mediumTimeFrameLabelDirection) < 0)
{
ObjectCreate(mediumTimeFrameLabelDirection, OBJ_LABEL, 0, 0, 0);
ObjectSet(mediumTimeFrameLabelDirection, OBJPROP_CORNER, 0);
//ObjectSet(mediumTimeFrameLabelDirection, OBJPROP_XDISTANCE, BlshDisplayX + ofset);
ObjectSet(mediumTimeFrameLabelDirection, OBJPROP_XDISTANCE, BlshDisplayX + 50);
ObjectSet(mediumTimeFrameLabelDirection, OBJPROP_YDISTANCE, BlshDisplayY+DisplayCount*(BlshfontSise+10));
ObjectSet(mediumTimeFrameLabelDirection, OBJPROP_BACK, false);
ObjectSetText(mediumTimeFrameLabelDirection, mediumBlshStatus, BlshfontSise, BlshfontName, BuyColour);
}//if (ObjectFind(mediumestTimeFrameLabelDirection) < 0)
DisplayCount++;
}//if (UseHighTimeFrame)
if (ObjectFind(tradingTimeFrameLabelName) < 0)
{
ObjectCreate(tradingTimeFrameLabelName, OBJ_LABEL, 0, 0, 0);
ObjectSet(tradingTimeFrameLabelName, OBJPROP_CORNER, 0);
//ObjectSet(tradingTimeFrameLabelName, OBJPROP_XDISTANCE, BlshDisplayX + ofset);
ObjectSet(tradingTimeFrameLabelName, OBJPROP_XDISTANCE, BlshDisplayX);
ObjectSet(tradingTimeFrameLabelName, OBJPROP_YDISTANCE, BlshDisplayY+DisplayCount*(BlshfontSise+10));
ObjectSet(tradingTimeFrameLabelName, OBJPROP_BACK, false);
tfDisplay = GetTimeFrameDisplay(TradingTimeFrame);
ObjectSetText(tradingTimeFrameLabelName, tfDisplay, BlshfontSise, BlshfontName, TradingTimeFrameLineColour);
}//if (ObjectFind(tradingTimeFrameLabelName) < 0)
if (ObjectFind(tradingTimeFrameLabelDirection) < 0)
{
ObjectCreate(tradingTimeFrameLabelDirection, OBJ_LABEL, 0, 0, 0);
ObjectSet(tradingTimeFrameLabelDirection, OBJPROP_CORNER, 0);
//ObjectSet(tradingTimeFrameLabelDirection, OBJPROP_XDISTANCE, BlshDisplayX + ofset);
ObjectSet(tradingTimeFrameLabelDirection, OBJPROP_XDISTANCE, BlshDisplayX + 50);
ObjectSet(tradingTimeFrameLabelDirection, OBJPROP_YDISTANCE, BlshDisplayY+DisplayCount*(BlshfontSise+10));
ObjectSet(tradingTimeFrameLabelDirection, OBJPROP_BACK, false);
ObjectSetText(tradingTimeFrameLabelDirection, tradingBlshStatus, BlshfontSise, BlshfontName, BuyColour);
}//if (ObjectFind(tradingestTimeFrameLabelDirection) < 0)
}//if (UseBuyLowSellHigh)
//Call sq's show trades indi
//iCustom(NULL, 0, "SQ_showTrades",Magic, 0,0);
//----
return(0);
}