Comments that do not relate to the "General rules and best pratices of the Forum.", have been moved into this topic.
Hi can i get help about my code to solve it?
LORD_TRADER #:
Hi can i get help about my code to solve it?
Hi can i get help about my code to solve it?
//+------------------------------------------------------------------+ //| MA_Cross.mq5 | //| n Copyright © 2021, Bing | //| https://www.bing.com | //+------------------------------------------------------------------+ #property copyright "Bing" #property link "https://www.bing.com" #property version "1.00" #property strict //--- input parameters input int FastMAPeriod = 10; // Fast MA period input int SlowMAPeriod = 20; // Slow MA period input double RiskRewardRatio = 6; // Risk-reward ratio //--- indicator buffers double FastMABuffer[]; double SlowMABuffer[]; //--- global variables int FastMAHandle; int SlowMAHandle; double Point; ENUM_ORDER_TYPE OrderType; double StopLoss; double TakeProfit; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- create handles FastMAHandle = iMA(_Symbol, _Period, FastMAPeriod, 0, MODE_EMA, PRICE_CLOSE); SlowMAHandle = iMA(_Symbol, _Period, SlowMAPeriod, 0, MODE_EMA, PRICE_CLOSE); //--- check for errors if(FastMAHandle == INVALID_HANDLE || SlowMAHandle == INVALID_HANDLE) { Print("Error creating handles"); return(INIT_FAILED); } //--- set indicator buffers SetIndexBuffer(0, FastMABuffer, INDICATOR_DATA); SetIndexBuffer(1, SlowMABuffer, INDICATOR_DATA); //--- set point value Point = _Point; if(Digits() == 3 || Digits() == 5) Point *= 10; //--- no orders initially OrderType = ORDER_TYPE_BUY + ORDER_TYPE_SELL + 1; //--- succeed return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- delete handles IndicatorRelease(FastMAHandle); IndicatorRelease(SlowMAHandle); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- copy data to buffers if(CopyBuffer(FastMAHandle, 0, 0, 2, FastMABuffer) <= 0 || CopyBuffer(SlowMAHandle, 0, 0, 2, SlowMABuffer) <= 0) return; //--- check for crossover if(FastMABuffer[1] < SlowMABuffer[1] && FastMABuffer[0] > SlowMABuffer[0]) OrderType = ORDER_TYPE_BUY; // buy signal else if(FastMABuffer[1] > SlowMABuffer[1] && FastMABuffer[0] < SlowMABuffer[0]) OrderType = ORDER_TYPE_SELL; // sell signal else OrderType = ORDER_TYPE_BUY + ORDER_TYPE_SELL + 1; // no signal //--- check for open orders if(PositionSelect(_Symbol)) { //--- update stop loss and take profit if(PositionGetDouble(POSITION_SL) != StopLoss || PositionGetDouble(POSITION_TP) != TakeProfit) { if(!PositionModify(PositionGetInteger(POSITION_TICKET), StopLoss, TakeProfit)) Print("Error modifying order: ", GetLastError()); } //--- check for exit signal if((PositionGetInteger(POSITION_TYPE) == ORDER_TYPE_BUY && OrderType == ORDER_TYPE_SELL) || (PositionGetInteger(POSITION_TYPE) == ORDER_TYPE_SELL && OrderType == ORDER_TYPE_BUY)) { if(!PositionClose(PositionGetInteger(POSITION_TICKET))) Print("Error closing order: ", GetLastError()); } return; } //--- check for entry signal if(OrderType == ORDER_TYPE_BUY || OrderType == ORDER_TYPE_SELL) { //--- calculate lot size based on risk percentage double RiskPercent = 1; // risk 1% of account balance per trade double AccountBalance = AccountInfoDouble(ACCOUNT_BALANCE); double AccountRisk = AccountBalance * RiskPercent / 100; double LotSize = NormalizeDouble(AccountRisk / (100 * Point * RiskRewardRatio), 2); //--- calculate stop loss and take profit if(OrderType == ORDER_TYPE_BUY) { StopLoss = NormalizeDouble(Bid - 100 * Point, Digits()); TakeProfit = NormalizeDouble(Bid + 100 * Point * RiskRewardRatio, Digits()); } else { StopLoss = NormalizeDouble(Ask + 100 * Point, Digits()); TakeProfit = NormalizeDouble(Ask - 100 * Point * RiskRewardRatio, Digits()); } //--- open order ulong ticket; if(!OrderSendAsync(_Symbol, OrderType, LotSize, StopLoss, TakeProfit, "MA Cross")); }error in line 74 and 135
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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