'}' - unexpected end of program KILANGIFX.mq5 174 1
'{' - unbalanced parentheses KILANGIFX.mq5 58 1
'CheckInputs' - undeclared identifier KILANGIFX.mq5 39 10
')' - expression expected KILANGIFX.mq5 39 22
Abbas Mussa:
'}' - unexpected end of program KILANGIFX.mq5 174 1
'{' - unbalanced parentheses KILANGIFX.mq5 58 1
'CheckInputs' - undeclared identifier KILANGIFX.mq5 39 10
')' - expression expected KILANGIFX.mq5 39 22
//+------------------------------------------------------------------+ //| KILANGIFX.mq5 | //| Copyright 2023, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2023, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" //+------------------------------------------------------------------+ //| Include | //+------------------------------------------------------------------+ #include <Trade\Trade.mqh> //+------------------------------------------------------------------+ //| Inputs | //+------------------------------------------------------------------+ static input long InpMagicnumber = 546872; // magicnumber static input double InpLots = 0.01; // lotsize input int InpBars = 20; // bat for high/low input int InpStopLoss = 200; //bars loss in points (0=off) input int InpTakeProfit = 0; //take profit in points (0=off) //+------------------------------------------------------------------+ //| Global variables | //+------------------------------------------------------------------+ double high = 0; // highest price of the last N bars double low = 0; // lowest price of the last N bars MqlTick currentTick, previousTick; CTrade trade; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //check for user imput if(! CheckInputs()) { return INIT_PARAMETERS_INCORRECT; } // set magicnumber trade.SetExpertMagicNumber(InpMagicnumber); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { // get tick previousTick = currentTick; if(!SymbolInfoTick(_Symbol, currentTick)) { Print("Failed to get current tick"); return; } // count open positions int cntBuy, cntSell; if(!CountopenPosition(cntBuy, cntSell)) { return; } // check for buy position if(cntBuy == 0 && high != 0 && previousTick.ask < high && currentTick.ask >= high) { Print("Open buy position"); } // check for sell position if(cntSell == 0 && low != 0 && previousTick.bid > low && currentTick.bid <= low) { Print("Open sell position"); } } //+------------------------------------------------------------------+ //| Functions | //+------------------------------------------------------------------+ // check user input bool CheckInputs() { if(InpMagicnumber <= 0) { Alert("Wrong inputs: Magicnumber <= 0"); return false; } if(InpLots <= 0) { Alert("Wrong inputs: Lot size <= 0"); return false; } if(InpBars <= 0) { Alert("Wrong inputs: Bars <= 0"); return false; } if(InpStopLoss < 0) { Alert("Wrong inputs: Stop loss < 0"); return false; } if(InpTakeProfit < 0) { Alert("Wrong inputs: Take profit < 0"); return false; } return true; } // count open positions bool CountopenPosition(int &cntBuy, int &cntSell) { cntBuy = 0; cntSell = 0; int total = PositionsTotal(); for(int i = total - 1; i >= 0; i--) { ulong ticket = PositionGetTicket(1); if(ticket <= 0) { Print("Failed to get position ticket"); return false; } if(!PositionSelectByTicket(ticket)) { Print("Failed to select position"); return false; } long magic; if(!PositionGetInteger(POSITION_MAGIC, magic)) { Print("Failed to get position magicnumber"); return false; } if(magic == InpMagicnumber) { long type; if(!PositionGetInteger(POSITION_TYPE, type)) { Print("Failed to get position type"); return false; } if(type == POSITION_TYPE_BUY) { cntBuy++; } if(type == POSITION_TYPE_SELL) { cntSell++; } } } return true; } // normalize price bool NormalizePrice(double & price) { double tickSize = 0; if(!SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE, tickSize)) { Print("Failed to get tick size"); return false; } price = NormalizeDouble(MathRound(price / tickSize) * tickSize, _Digits); return true; } // close positions bool ClosePosition(int all_buy_sell) { int total = PositionsTotal(); for(int i = total - 1; i >= 0; i--) { ulong ticket = PositionGetTicket(1); if(ticket <= 0) { Print("Failed to get position ticket"); return false; } if(!PositionSelectByTicket(ticket)) { Print("Failed to select position"); return false; } long magic; if(!PositionGetInteger(POSITION_MAGIC, magic)) { Print("Failed to get position magicnumber"); return false; } if(magic == InpMagicnumber) { long type; if(!PositionGetInteger(POSITION_TYPE, type)) { Print("Failed to get position type"); return false; } if(all_buy_sell == 1 && type == POSITION_TYPE_SELL) { continue; } if(all_buy_sell == 2 && type == POSITION_TYPE_BUY) { continue; } trade.PositionClose(ticket); if(trade.ResultRetcode() != TRADE_RETCODE_DONE) { Print("Failed to close position. ticket:", (string)ticket, " result:", (string)trade.ResultRetcode(), ":", trade.CheckResultRetcodeDescription()); } } } return true; } //+------------------------------------------------------------------+
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register