If you need help with your code, then show your code.
We cannot read your mind nor see your computer.
Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
No free help (2017)
Or pay someone. Top of every page is the link Freelance.
Hiring to write script - General - MQL5 programming forum (2018)
We're not going to code it for you (although it could happen if you are lucky or the issue is interesting).
No free help (2017)
If you need help with your code, then show your code.
We cannot read your mind nor see your computer.
#define BUYSIGNAL "Buy now"
#define SELLSIGNAL "Sell now"
#define EXITSELL "Exit sell"
#define EXITBUY "Exit Buy"
#include <stdlib.mqh>
enum crossover_enum
{
Immediately,
candle_close, //Candle close
};
enum close_op
{
ma_cross_exit, //MA crossover
} ;
extern string sep1 = "========================================="; //=============
extern string sep2 = " GENERAL SETTINGS"; //*******************
extern string sep3 = "========================================="; //=============
extern int Magic = 345678;
extern string EA_Comment = "TMA ALLIGNED CROSS"; //Order Comment
extern string sep4 = "========================================="; //=============
extern string sep5 = " TRADE SETTINGS"; //*******************
extern string sep6 = "========================================="; //=============
extern int Slippage = 3;
extern bool use_martingale = true;
extern double martingale = 2.0; //Martingale
extern double Risk = 1; //Max Risk %
extern double Lots = 0.1; //Fixed lots (if Auto Lot = false
extern int StopLoss = 150; //Stoploss (in points)
extern int TakeProfit = 250; //Takeprofit (in points)
extern double profit_goal = 2.00; //Profit goal in deposit currency
extern bool Max_loss = -1.00; //Loss goal in deposit currency
extern string sep7 = "========================================="; //=============
extern string sep8 = " TIME SETTINGS"; //*******************
extern string sep9 = "========================================="; //=============
extern ENUM_DAY_OF_WEEK Start_Day = 1;//Start Day
extern ENUM_DAY_OF_WEEK End_Day = 5;//End Day
extern string sep10 = "========================================="; //=============
extern string sep11 = " MOVING AVERAGE SETTINGS"; //*******************
extern string sep12 = "========================================="; //=============
extern crossover_enum crossover_shift = Immediately; //Select MA Crossover
extern close_op exit_trade = ma_cross_exit; //Close trade options
extern string MA1_Info = "-- Moving_average_1 --"; //First MA
extern int MA1_ma_period = 1; //Period
extern int MA1_ma_shift = 0; //Shift
extern ENUM_MA_METHOD MA1_ma_method = MODE_EMA; //MA method
extern ENUM_APPLIED_PRICE MA1_ma_price = PRICE_CLOSE; //Apply to
extern string MA2_Info = "-- Moving_average_2 --"; //second MA
extern int MA2_ma_period = 3; //Period
extern int MA2_ma_shift = 0; //Shift
extern ENUM_MA_METHOD MA2_ma_method = MODE_EMA; //MA method
extern ENUM_APPLIED_PRICE MA2_ma_price = PRICE_CLOSE; //Apply to
extern string MA3_Info = "-- Moving_average_3 --"; //third MA
extern int MA3_ma_period = 5; //Period
extern int MA3_ma_shift = 0; //Shift
extern ENUM_MA_METHOD MA3_ma_method = MODE_EMA; //MA method
extern ENUM_APPLIED_PRICE MA3_ma_price = PRICE_CLOSE; //Apply to
extern string MA4_Info = "-- Moving_average_4--"; //Fourth MA
extern int MA4_ma_period = 7; //Period
extern int MA4_ma_shift = 0; //Shift
extern ENUM_MA_METHOD MA4_ma_method = MODE_EMA; //MA method
extern ENUM_APPLIED_PRICE MA4_ma_price = PRICE_CLOSE; //Apply too
extern string MA5_Info = "-- Moving_average_5 --"; //Fifth MA
extern int MA5_ma_period = 9; //Period
extern int MA5_ma_shift = 0; //Shift
extern ENUM_MA_METHOD MA5_ma_method = MODE_EMA; //MA method
extern ENUM_APPLIED_PRICE MA5_ma_price = PRICE_CLOSE; //Apply to
extern string MA6_Info = "-- Moving_average_6 --"; //Sixth MA
extern int MA6_ma_period = 11; //Period
extern int MA6_ma_shift = 0; //Shift
extern ENUM_MA_METHOD MA6_ma_method = MODE_EMA; //MA method
extern ENUM_APPLIED_PRICE MA6_ma_price = PRICE_CLOSE; //Apply to
extern string MA7_Info = "-- Moving_average_7 --"; //Seventh MA
extern int MA7_ma_period = 13; //Period
extern int MA7_ma_shift = 0; //Shift
extern ENUM_MA_METHOD MA7_ma_method = MODE_EMA; //MA method
extern ENUM_APPLIED_PRICE MA7_ma_price = PRICE_CLOSE; //Apply to
int ErrCode;
datetime open_time;
//+------------------------------------------------------------------+
struct trade_data
{
int positions;
bool position_active;
datetime last_pos_time;
int spread;
int stoplevel;
};
trade_data data;
//+------------------------------------------------------------------+
int OnInit()
{
ChartSetInteger(0,CHART_MODE,CHART_CANDLES);
ChartSetInteger(0,CHART_SHOW_GRID,false);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
void OnTick()
{
data = GetData(data);
bool close = CheckForClose();
if(close)
{
data = GetData(data);
}
CheckForOpen();
}
//+------------------------------------------------------------------+
void CheckForOpen()
{
if(data.last_pos_time >= Time[0])return;
if(data.positions > 0)return;
string signal = GetEntrySignal();
if(signal == "")return;
if(signal == BUYSIGNAL)
{
BUY();
Comment("tyui");
return;
}
if(signal == SELLSIGNAL)
{
SELL();
return;
}
}
//+-------------------------------------------------------------------+
bool CheckForClose()
{
string signal = GetEntrySignal();
if(signal == "")return false;
bool closed = false;
for(int i = OrdersTotal() - 1; i >= 0; i--)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))continue;
if(OrderSymbol() != Symbol())continue;
if(OrderMagicNumber() != Magic)continue;
if(OrderType() == OP_BUY)
{
if(signal == SELLSIGNAL)
{
if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,clrWhite))
{
ErrCode = GetLastError();
Print("Unable to close Buy order due to ",ErrorDescription(ErrCode));
}
else closed = true;
}
}
if(OrderType() == OP_SELL)
{
if(signal == BUYSIGNAL)
{
if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,clrWhite))
{
ErrCode = GetLastError();
Print("Unable to close Sell order due to ",ErrorDescription(ErrCode));
}
else closed = true;
}
}
}
return closed;
}
//+------------------------------------------------------------------+
string GetEntrySignal()
{
string signal = "";
int shift = 1;
if(crossover_shift == Immediately)shift = 0;
//Initialiaze moving averages
double MA1 = iMA(_Symbol,0, MA1_ma_method, MA1_ma_shift, MA1_ma_method, MA1_ma_price,shift);
double MA2 = iMA(_Symbol,0, MA2_ma_method, MA2_ma_shift, MA2_ma_method, MA2_ma_price,shift);
double MA3 = iMA(_Symbol,0, MA3_ma_method, MA3_ma_shift, MA3_ma_method, MA3_ma_price,shift);
double MA4 = iMA(_Symbol,0, MA4_ma_method, MA4_ma_shift, MA4_ma_method, MA4_ma_price,shift);
double MA5 = iMA(_Symbol,0, MA5_ma_method, MA5_ma_shift, MA5_ma_method, MA5_ma_price,shift);
double MA6 = iMA(_Symbol,0, MA6_ma_method, MA6_ma_shift, MA6_ma_method, MA6_ma_price,shift);
double MA7 = iMA(_Symbol,0, MA7_ma_method, MA7_ma_shift, MA7_ma_method, MA7_ma_price,shift);
//Buy signal
if(MA1 > MA7)
{
if( MA1 < MA3 && MA3 < MA4 && MA4 < MA5 < MA5 < MA6 && MA6 < MA7)signal = BUYSIGNAL;
}
return signal;
}
//+-------------------------------------------------------------+
void SELL()
{
double SLoss = 0;
double TProfit = 0;
RefreshRates();
if(StopLoss > 0)
{
SLoss = Ask + (StopLoss * Point());
if(SLoss - Ask <= data.stoplevel * Point)SLoss = Ask + ((data.stoplevel + 2) * Point);
SLoss = NormalizeDouble(SLoss,_Digits);
}
if(TakeProfit > 0)
{
TProfit = Bid - (TakeProfit * Point());
if(Bid - TProfit <= data.stoplevel * Point)TProfit = Bid - ((data.stoplevel + 2) * Point);
TProfit = NormalizeDouble(TProfit,_Digits);
}
double lots = LotOptimised(MathAbs(Ask - SLoss));
int sell = OrderSend(Symbol(),OP_SELL,lots,Bid,Slippage,0,0,EA_Comment,Magic,0,clrRed);
if(sell < 0)
{
ErrCode = GetLastError();
Print("Unable to open sell position, ",ErrorDescription(ErrCode));
}
else if(sell > 0)
{
ModifyTPSL(sell,SLoss,TProfit);
Print("sell placed successfully ",Magic);
open_time = TimeCurrent();
}
}
//+------------------------------------------------------------+
void BUY()
{
double SLoss = 0;
double TProfit = 0;
RefreshRates();
if(StopLoss > 0)
{
SLoss = Bid - (StopLoss * Point());
if(Bid - SLoss <= data.stoplevel * Point)SLoss = Bid - ((data.stoplevel + 2) * Point);
SLoss = NormalizeDouble(SLoss,_Digits);
}
if(TakeProfit > 0)
{
TProfit = Ask + (TakeProfit * Point());
if(TProfit - Ask <= data.stoplevel * Point)TProfit = Ask + ((data.stoplevel + 2) * Point);
TProfit = NormalizeDouble(TProfit,_Digits);
}
double lots = LotOptimised(MathAbs(Ask - SLoss));
int buy = OrderSend(Symbol(),OP_BUY,lots,Ask,Slippage,0,0,EA_Comment,Magic,0,clrBlue);
if(buy < 0)
{
ErrCode = GetLastError();
Print("Unable to open buy position, ",ErrorDescription(ErrCode));
}
else if(buy > 0)
{
ModifyTPSL(buy,SLoss,TProfit);
Print("buy placed successfully ",Magic);
open_time = TimeCurrent();
}
}
//+----------------------------------------------------+
void ModifyTPSL(int ticket,double SL, double TP)
{
if(!OrderSelect(ticket,SELECT_BY_TICKET))return;
if(!OrderModify(ticket,OrderOpenPrice(),SL,TP,0))
{
ErrCode = GetLastError();
Print("Unable to set TP and SL, ",ErrorDescription(ErrCode));
}
}
//+-----------------------------------------------------+
double LotOptimised(double stoploss)
{
double Lot = Lots;
double RiskMoney = (Risk * 0.01) * AccountBalance();
double Tickvalue = MarketInfo(Symbol(),MODE_TICKVALUE);
double Ticksize = MarketInfo(Symbol(),MODE_TICKSIZE);
Lot = RiskMoney / (stoploss * Tickvalue / Ticksize);
double minLot = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
double maxLot = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
double LotStep = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);
Lot = MathRound(Lot/LotStep) * LotStep;
Lot = MathMin(MathMax(Lot,minLot),maxLot);
return Lot;
}
//+-------------------------------------------------------+
trade_data GetData(trade_data &o_data)
{
bool is_position = false;
int pos = 0;
datetime last_time = 0;
for(int i = 0; i < OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))break;
if(OrderSymbol() != Symbol())continue;
if(OrderMagicNumber() != Magic)continue;
is_position = true;
pos++;
if(OrderOpenTime() > last_time)last_time = OrderOpenTime();
}
o_data.position_active = is_position;
o_data.positions = pos;
o_data.last_pos_time = last_time;
o_data.spread = (int)MarketInfo(Symbol(),MODE_SPREAD);
o_data.stoplevel = (int)MarketInfo(Symbol(),MODE_STOPLEVEL);
return o_data;
}
Here is the full code I need help in writing the arrays to hold the moving averages value, and also how I can copy the buffers and store their values
...
Pleas edit your post -
Forum on trading, automated trading systems and testing trading strategies
A zigzag that creates horizontal lines.
Fernando Carreiro, 2023.02.21 20:35
Please edit your post (don't create a new post) and replace your code properly (with "</>" or Alt-S), or attach the original file directly with the "+ Attach file" button below the text box.
NB! Very important! DO NOT create a new post. EDIT your original post.
-
Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
Messages Editor -
Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, I have been coding an EA with 7 moving averages periods but I am having trouble in initializing them . The conditions for buy is when the lowest ma period crosses the highest upwards and the other 5 align themselves facing upwards. Kindly who can assist me with this code. Note: It's not a crossover. The periods are 1,3,5,7,9,11,13. I need help on how I can write the code to hold the moving averages period, buffers to copy and store their values before I input their buy and sell conditions
Here is the complete code
#define BUYSIGNAL "Buy now"
#define SELLSIGNAL "Sell now"
#define EXITSELL "Exit sell"
#define EXITBUY "Exit Buy"
#include <stdlib.mqh>
enum crossover_enum
{
Immediately,
candle_close, //Candle close
};
enum close_op
{
ma_cross_exit, //MA crossover
} ;
extern string sep1 = "========================================="; //=============
extern string sep2 = " GENERAL SETTINGS"; //*******************
extern string sep3 = "========================================="; //=============
extern int Magic = 345678;
extern string EA_Comment = "TMA ALLIGNED CROSS"; //Order Comment
extern string sep4 = "========================================="; //=============
extern string sep5 = " TRADE SETTINGS"; //*******************
extern string sep6 = "========================================="; //=============
extern int Slippage = 3;
extern bool use_martingale = true;
extern double martingale = 2.0; //Martingale
extern double Risk = 1; //Max Risk %
extern double Lots = 0.1; //Fixed lots (if Auto Lot = false
extern int StopLoss = 150; //Stoploss (in points)
extern int TakeProfit = 250; //Takeprofit (in points)
extern double profit_goal = 2.00; //Profit goal in deposit currency
extern bool Max_loss = -1.00; //Loss goal in deposit currency
extern string sep7 = "========================================="; //=============
extern string sep8 = " TIME SETTINGS"; //*******************
extern string sep9 = "========================================="; //=============
extern ENUM_DAY_OF_WEEK Start_Day = 1;//Start Day
extern ENUM_DAY_OF_WEEK End_Day = 5;//End Day
extern string sep10 = "========================================="; //=============
extern string sep11 = " MOVING AVERAGE SETTINGS"; //*******************
extern string sep12 = "========================================="; //=============
extern crossover_enum crossover_shift = Immediately; //Select MA Crossover
extern close_op exit_trade = ma_cross_exit; //Close trade options
extern string MA1_Info = "-- Moving_average_1 --"; //First MA
extern int MA1_ma_period = 1; //Period
extern int MA1_ma_shift = 0; //Shift
extern ENUM_MA_METHOD MA1_ma_method = MODE_EMA; //MA method
extern ENUM_APPLIED_PRICE MA1_ma_price = PRICE_CLOSE; //Apply to
extern string MA2_Info = "-- Moving_average_2 --"; //second MA
extern int MA2_ma_period = 3; //Period
extern int MA2_ma_shift = 0; //Shift
extern ENUM_MA_METHOD MA2_ma_method = MODE_EMA; //MA method
extern ENUM_APPLIED_PRICE MA2_ma_price = PRICE_CLOSE; //Apply to
extern string MA3_Info = "-- Moving_average_3 --"; //third MA
extern int MA3_ma_period = 5; //Period
extern int MA3_ma_shift = 0; //Shift
extern ENUM_MA_METHOD MA3_ma_method = MODE_EMA; //MA method
extern ENUM_APPLIED_PRICE MA3_ma_price = PRICE_CLOSE; //Apply to
extern string MA4_Info = "-- Moving_average_4--"; //Fourth MA
extern int MA4_ma_period = 7; //Period
extern int MA4_ma_shift = 0; //Shift
extern ENUM_MA_METHOD MA4_ma_method = MODE_EMA; //MA method
extern ENUM_APPLIED_PRICE MA4_ma_price = PRICE_CLOSE; //Apply too
extern string MA5_Info = "-- Moving_average_5 --"; //Fifth MA
extern int MA5_ma_period = 9; //Period
extern int MA5_ma_shift = 0; //Shift
extern ENUM_MA_METHOD MA5_ma_method = MODE_EMA; //MA method
extern ENUM_APPLIED_PRICE MA5_ma_price = PRICE_CLOSE; //Apply to
extern string MA6_Info = "-- Moving_average_6 --"; //Sixth MA
extern int MA6_ma_period = 11; //Period
extern int MA6_ma_shift = 0; //Shift
extern ENUM_MA_METHOD MA6_ma_method = MODE_EMA; //MA method
extern ENUM_APPLIED_PRICE MA6_ma_price = PRICE_CLOSE; //Apply to
extern string MA7_Info = "-- Moving_average_7 --"; //Seventh MA
extern int MA7_ma_period = 13; //Period
extern int MA7_ma_shift = 0; //Shift
extern ENUM_MA_METHOD MA7_ma_method = MODE_EMA; //MA method
extern ENUM_APPLIED_PRICE MA7_ma_price = PRICE_CLOSE; //Apply to
int ErrCode;
datetime open_time;
//+------------------------------------------------------------------+
struct trade_data
{
int positions;
bool position_active;
datetime last_pos_time;
int spread;
int stoplevel;
};
trade_data data;
//+------------------------------------------------------------------+
int OnInit()
{
ChartSetInteger(0,CHART_MODE,CHART_CANDLES);
ChartSetInteger(0,CHART_SHOW_GRID,false);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
void OnTick()
{
data = GetData(data);
bool close = CheckForClose();
if(close)
{
data = GetData(data);
}
CheckForOpen();
}
//+------------------------------------------------------------------+
void CheckForOpen()
{
if(data.last_pos_time >= Time[0])return;
if(data.positions > 0)return;
string signal = GetEntrySignal();
if(signal == "")return;
if(signal == BUYSIGNAL)
{
BUY();
Comment("tyui");
return;
}
if(signal == SELLSIGNAL)
{
SELL();
return;
}
}
//+-------------------------------------------------------------------+
bool CheckForClose()
{
string signal = GetEntrySignal();
if(signal == "")return false;
bool closed = false;
for(int i = OrdersTotal() - 1; i >= 0; i--)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))continue;
if(OrderSymbol() != Symbol())continue;
if(OrderMagicNumber() != Magic)continue;
if(OrderType() == OP_BUY)
{
if(signal == SELLSIGNAL)
{
if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,clrWhite))
{
ErrCode = GetLastError();
Print("Unable to close Buy order due to ",ErrorDescription(ErrCode));
}
else closed = true;
}
}
if(OrderType() == OP_SELL)
{
if(signal == BUYSIGNAL)
{
if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,clrWhite))
{
ErrCode = GetLastError();
Print("Unable to close Sell order due to ",ErrorDescription(ErrCode));
}
else closed = true;
}
}
}
return closed;
}
//+------------------------------------------------------------------+
string GetEntrySignal()
{
string signal = "";
int shift = 1;
if(crossover_shift == Immediately)shift = 0;
//Initialiaze moving averages
double MA1 = iMA(_Symbol,0, MA1_ma_method, MA1_ma_shift, MA1_ma_method, MA1_ma_price,shift);
double MA2 = iMA(_Symbol,0, MA2_ma_method, MA2_ma_shift, MA2_ma_method, MA2_ma_price,shift);
double MA3 = iMA(_Symbol,0, MA3_ma_method, MA3_ma_shift, MA3_ma_method, MA3_ma_price,shift);
double MA4 = iMA(_Symbol,0, MA4_ma_method, MA4_ma_shift, MA4_ma_method, MA4_ma_price,shift);
double MA5 = iMA(_Symbol,0, MA5_ma_method, MA5_ma_shift, MA5_ma_method, MA5_ma_price,shift);
double MA6 = iMA(_Symbol,0, MA6_ma_method, MA6_ma_shift, MA6_ma_method, MA6_ma_price,shift);
double MA7 = iMA(_Symbol,0, MA7_ma_method, MA7_ma_shift, MA7_ma_method, MA7_ma_price,shift);
//Buy signal
if(MA1 > MA7)
{
if( MA1 < MA3 && MA3 < MA4 && MA4 < MA5 < MA5 < MA6 && MA6 < MA7)signal = BUYSIGNAL;
}
return signal;
}
//+-------------------------------------------------------------+
void SELL()
{
double SLoss = 0;
double TProfit = 0;
RefreshRates();
if(StopLoss > 0)
{
SLoss = Ask + (StopLoss * Point());
if(SLoss - Ask <= data.stoplevel * Point)SLoss = Ask + ((data.stoplevel + 2) * Point);
SLoss = NormalizeDouble(SLoss,_Digits);
}
if(TakeProfit > 0)
{
TProfit = Bid - (TakeProfit * Point());
if(Bid - TProfit <= data.stoplevel * Point)TProfit = Bid - ((data.stoplevel + 2) * Point);
TProfit = NormalizeDouble(TProfit,_Digits);
}
double lots = LotOptimised(MathAbs(Ask - SLoss));
int sell = OrderSend(Symbol(),OP_SELL,lots,Bid,Slippage,0,0,EA_Comment,Magic,0,clrRed);
if(sell < 0)
{
ErrCode = GetLastError();
Print("Unable to open sell position, ",ErrorDescription(ErrCode));
}
else if(sell > 0)
{
ModifyTPSL(sell,SLoss,TProfit);
Print("sell placed successfully ",Magic);
open_time = TimeCurrent();
}
}
//+------------------------------------------------------------+
void BUY()
{
double SLoss = 0;
double TProfit = 0;
RefreshRates();
if(StopLoss > 0)
{
SLoss = Bid - (StopLoss * Point());
if(Bid - SLoss <= data.stoplevel * Point)SLoss = Bid - ((data.stoplevel + 2) * Point);
SLoss = NormalizeDouble(SLoss,_Digits);
}
if(TakeProfit > 0)
{
TProfit = Ask + (TakeProfit * Point());
if(TProfit - Ask <= data.stoplevel * Point)TProfit = Ask + ((data.stoplevel + 2) * Point);
TProfit = NormalizeDouble(TProfit,_Digits);
}
double lots = LotOptimised(MathAbs(Ask - SLoss));
int buy = OrderSend(Symbol(),OP_BUY,lots,Ask,Slippage,0,0,EA_Comment,Magic,0,clrBlue);
if(buy < 0)
{
ErrCode = GetLastError();
Print("Unable to open buy position, ",ErrorDescription(ErrCode));
}
else if(buy > 0)
{
ModifyTPSL(buy,SLoss,TProfit);
Print("buy placed successfully ",Magic);
open_time = TimeCurrent();
}
}
//+----------------------------------------------------+
void ModifyTPSL(int ticket,double SL, double TP)
{
if(!OrderSelect(ticket,SELECT_BY_TICKET))return;
if(!OrderModify(ticket,OrderOpenPrice(),SL,TP,0))
{
ErrCode = GetLastError();
Print("Unable to set TP and SL, ",ErrorDescription(ErrCode));
}
}
//+-----------------------------------------------------+
double LotOptimised(double stoploss)
{
double Lot = Lots;
double RiskMoney = (Risk * 0.01) * AccountBalance();
double Tickvalue = MarketInfo(Symbol(),MODE_TICKVALUE);
double Ticksize = MarketInfo(Symbol(),MODE_TICKSIZE);
Lot = RiskMoney / (stoploss * Tickvalue / Ticksize);
double minLot = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
double maxLot = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
double LotStep = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);
Lot = MathRound(Lot/LotStep) * LotStep;
Lot = MathMin(MathMax(Lot,minLot),maxLot);
return Lot;
}
//+-------------------------------------------------------+
trade_data GetData(trade_data &o_data)
{
bool is_position = false;
int pos = 0;
datetime last_time = 0;
for(int i = 0; i < OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))break;
if(OrderSymbol() != Symbol())continue;
if(OrderMagicNumber() != Magic)continue;
is_position = true;
pos++;
if(OrderOpenTime() > last_time)last_time = OrderOpenTime();
}
o_data.position_active = is_position;
o_data.positions = pos;
o_data.last_pos_time = last_time;
o_data.spread = (int)MarketInfo(Symbol(),MODE_SPREAD);
o_data.stoplevel = (int)MarketInfo(Symbol(),MODE_STOPLEVEL);
return o_data;
}