i tried to combine the code you learned me with the one in the example. That is my try. i Hope i am in a good way.
Thank's for the teaching!
I really appreciate it.
1. Please insert the code correctly: when editing a message, press the button and paste your code into the pop-up window. (The first time I corrected your message)
2. Now we need the next step: state what we are looking for: the last three deals?
1. Please insert the code correctly: when editing a message, press the button and paste your code into the pop-up window. (The first time I corrected your message)
2. Now we need the next step: state what we are looking for: the last three deals?
so i need to change the function
for (uint i=0;i<total;i++)
to
for (uint i=total-1;i>=total-3;i--)
so that we take only the last 3 deals? and then modify my last if LIKE
if (profit<0 && HistoryDealGetDouble(HistoryDealGetTicket(i)-1,DEAL_PROFIT)<0)
{lose_streak +=1;
}//ifelse
{win_streak=true;
}//else
so that i can count and check if there is a losestreak?
I am a bit confused. Thats where i exactly losing control.
1. Please insert the code correctly: when editing a message, press the button and paste your code into the pop-up window. (The first time I corrected your message)
2. Now we need the next step: state what we are looking for: the last three deals?
#include <Trade/Trade.mqh>
int EMA_21_M5 = 0;
double ema_21[];
CTrade trade;
ulong trade_ticket = 0;
intOnInit(){
//setting up ema21close
EMA_21_M5 = iMA(_Symbol,_Period, 21, 0, MODE_EMA,PRICE_CLOSE);
ArraySetAsSeries(ema_21, true);
return (INIT_SUCCEEDED);
}
voidOnTick()
{
datetime time_local = TimeLocal();
string hoursAndMinutes = TimeToString(time_local,TIME_MINUTES);
MqlRates PriceInformation[];
CopyBuffer(EMA_21_M5, 0, 1, 5, ema_21);
ArraySetAsSeries(PriceInformation, true);
//taking real time data for the symbol we wantint Data=CopyRates(Symbol(), Period(), 0, Bars(Symbol(), Period()), PriceInformation);
if (PositionSelectByTicket(trade_ticket) == false) trade_ticket = 0;
MqlDateTime STime;
TimeToStruct(time_local,STime);
STime.hour=0;
STime.min=0;
STime.sec=0;
datetime time_start_day=StructToTime(STime);
HistorySelect(time_start_day,time_local+3600*24*3);
uint total=HistoryDealsTotal();
ulong ticket=0;
double price;
double profit;
datetime time;
int lose_streak=0;
bool win_streak=false;
long type;
long entry;
for (uint i=total-1;i==total-3;i--)
{
if(ticket=HistoryDealGetTicket(i)>0)
{
profit=HistoryDealGetDouble(ticket,DEAL_PROFIT);
Print("the ticket number is: ",ticket," and the profit is: ",profit);
if(profit<0)
{
lose_streak =1;
}//inside ifelseif(profit<0 && HistoryDealGetDouble(HistoryDealGetTicket(i)-1,DEAL_PROFIT)<0)
{
lose_streak = 2;
}//else if no1elseif(profit<0 &&HistoryDealGetDouble(HistoryDealGetTicket(i)-1,DEAL_PROFIT)<0 && HistoryDealGetDouble(HistoryDealGetTicket(i)-2,DEAL_PROFIT)<0)
{
lose_streak = 3;
}//else if no2else
{
win_streak = true;
Sleep(18000000);
win_streak=false;
lose_streak = 0;
}//else
}//if
}//forif ((StringSubstr(hoursAndMinutes,0,5) > "09:00") && (StringSubstr(hoursAndMinutes,0,5)< "13:00")){
if (ema_21[1] > PriceInformation[1].open && ema_21[1] < PriceInformation[1].close && trade_ticket <= 0 && lose_streak==0){
//ask is the real time price we are going to have action (buy)double ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits);
//STOP LOSS Variabledouble sl = ask-50*_Point;
//TAKE PROFIT Variabledouble tp = ask+50*_Point;
trade.Buy(0.10,//setting up the lottage_Symbol,ask,sl,tp,NULL);
trade_ticket = trade.ResultOrder();
Sleep(300000);
}//ifelseif(ema_21[1] > PriceInformation[1].open && ema_21[1] < PriceInformation[1].close && trade_ticket <= 0 && lose_streak==1)
{
//ask is the real time price we are going to have action (buy)double ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits);
//STOP LOSS Variabledouble sl = ask-50*_Point;
//TAKE PROFIT Variabledouble tp = ask+50*_Point;
trade.Buy(0.20,//setting up the lottage_Symbol,ask,sl,tp,NULL);
trade_ticket = trade.ResultOrder();
Sleep(300000);
}//else if no1elseif(ema_21[1] > PriceInformation[1].open && ema_21[1] < PriceInformation[1].close && trade_ticket <= 0 && lose_streak==2)
{
//ask is the real time price we are going to have action (buy)double ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits);
//STOP LOSS Variabledouble sl = ask-50*_Point;
//TAKE PROFIT Variabledouble tp = ask+50*_Point;
trade.Buy(0.30,//setting up the lottage_Symbol,ask,sl,tp,NULL);
trade_ticket = trade.ResultOrder();
Sleep(300000);
}//else if no2elseif (ema_21[1]<PriceInformation[1].open && ema_21[1]>PriceInformation[1].close && trade_ticket <= 0 && lose_streak==0 ){
//ask is the real time price we are going to have action (sell)double bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
//STOP LOSS Variabledouble sl = bid+50*_Point;
//TAKE PROFIT Variabledouble tp = bid-50*_Point;
trade.Sell(0.10,//setting up the lottage_Symbol,bid,sl,tp,NULL);
trade_ticket = trade.ResultOrder();
Sleep(300000);
}//else if no3elseif(ema_21[1]<PriceInformation[1].open && ema_21[1]>PriceInformation[1].close && trade_ticket <= 0 && lose_streak==1 )
{
//ask is the real time price we are going to have action (sell)double bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
//STOP LOSS Variabledouble sl = bid+50*_Point;
//TAKE PROFIT Variabledouble tp = bid-50*_Point;
trade.Sell(0.20,//setting up the lottage_Symbol,bid,sl,tp,NULL);
trade_ticket = trade.ResultOrder();
Sleep(300000);
}//else if no4elseif(ema_21[1]<PriceInformation[1].open && ema_21[1]>PriceInformation[1].close && trade_ticket <= 0 && lose_streak==2 )
{
//ask is the real time price we are going to have action (sell)double bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
//STOP LOSS Variabledouble sl = bid+50*_Point;
//TAKE PROFIT Variabledouble tp = bid-50*_Point;
trade.Sell(0.30,//setting up the lottage_Symbol,bid,sl,tp,NULL);
trade_ticket = trade.ResultOrder();
Sleep(300000);
}//else if no5
}//if
}//ontick
so this is my whole try makking it work. but it doesnt. any help will be aprecciated
Suggestion: Create functions to make analysing and editing the code easier.
thnx for your reply. i am trying to find out a way to make it work since you commented till now.The things that are missing are:
1)look back to the current days history and count losestreak
2)set up the lotsize of the bet depends on the losestreak that we have
3)if we win dont trade until next day at 9:00 in the morning
4)i want to make it trade only in the candle opening because if it is in atrade that it hits tp or sl and previous candle gives trade signal it takes the trade and thats not very profitable as i have checked it manually during the last months.
Thank's for your time.
Really appreciate it!
Here is my code:
#include <Trade/Trade.mqh>
int EMA_21_M5 = 0;
double ema_21[];
//needed so that we can trade
CTrade trade;
ulong trade_ticket = 0;
intOnInit(){
//setting up ema21close
EMA_21_M5 = iMA(_Symbol,_Period, 21, 0, MODE_EMA,PRICE_CLOSE);
ArraySetAsSeries(ema_21, true);
return (INIT_SUCCEEDED);
}
voidOnTick()
{
// get the local timedatetime time = TimeLocal();
//format the time and create a stringstring hoursAndMinutes = TimeToString(time,TIME_MINUTES);
MqlRates PriceInformation[];
CopyBuffer(EMA_21_M5, 0, 1, 5, ema_21);
ArraySetAsSeries(PriceInformation, true);
//taking real time data for the symbol we wantint Data=CopyRates(Symbol(), Period(), 0, Bars(Symbol(), Period()), PriceInformation);
if (PositionSelectByTicket(trade_ticket) == false) trade_ticket = 0;
//setting up the timeline we want our bot to take tradesif ((StringSubstr(hoursAndMinutes,0,5) > "09:00") && (StringSubstr(hoursAndMinutes,0,5)< "13:00")){
//setting up buyif (ema_21[1] > PriceInformation[1].open && ema_21[1] < PriceInformation[1].close && trade_ticket <= 0){
//ask is the real time price we are going to have action (buy)double ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits);
//STOP LOSS Variabledouble sl = ask-50*_Point;
//TAKE PROFIT Variabledouble tp = ask+50*_Point;
trade.Buy(0.10,//setting up the lottage_Symbol,ask,sl,tp,NULL);
trade_ticket = trade.ResultOrder();
//Sleep(300000);
}
//setting up sellelseif (ema_21[1]<PriceInformation[1].open && ema_21[1]>PriceInformation[1].close && trade_ticket <= 0){
//bid is the real time price we are going to have action (sell)double bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
//STOP LOSS Variabledouble sl = bid+50*_Point;
//TAKE PROFIT Variabledouble tp = bid-50*_Point;
trade.Sell(0.10,//setting up the lottage_Symbol,bid,sl,tp,NULL);
trade_ticket = trade.ResultOrder();
//Sleep(300000);
}
}
}
thnx for your reply. i am trying to find out a way to make it work since you commented till now.The things that are missing are:
1)look back to the current days history and count losestreak
2)set up the lotsize of the bet depends on the losestreak that we have
3)if we win dont trade until next day at 9:00 in the morning
4)i want to make it trade only in the candle opening because if it is in atrade that it hits tp or sl and previous candle gives trade signal it takes the trade and thats not very profitable as i have checked it manually during the last months.
Thank's for your time.
Really appreciate it!
Here is my code:
The EA attached to the previous post does all of that ?!
The EA attached to the previous post does all of that ?!
ok i made some changes that i needed and the program it seems to be working perfectly. Buy i have one question. Can you explain me why the lot size is going from 0.1 to 0.3 to 0.5 instead of 0.1 to 0.2 to 0.4?
i am trying to make it increase 0.1 each time for the losestreak.
the thing that i changed is the lotsize=0.1 from 0.2 in your programm and i added sl tp + that i dont want the position to close if another signal appears.
/////ask is the real time price we are going to have action (buy)double ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits);
//STOP LOSS Variabledouble sl = ask-50*_Point;
//TAKE PROFIT Variabledouble tp = ask+50*_Point;
/////bid is the real time price we are going to have action (sell)double bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
//STOP LOSS Variabledouble sl_sell = bid+50*_Point;
//TAKE PROFIT Variabledouble tp_sell = bid-50*_Point;
//---if(tradeTime && type==WRONG_VALUE && signal==SIGNAL_BULL)
if(trade.Buy(0.1+LotSize*losses,_Symbol,ask,sl,tp,NULL))
preTime=curTime;
//---if(tradeTime && type==WRONG_VALUE && signal==SIGNAL_BEAR)
if(trade.Sell(0.1+LotSize*losses,_Symbol,bid,sl_sell,tp_sell,NULL))
preTime=curTime;
//---///if(type==POSITION_TYPE_BUY && signal==SIGNAL_BEAR)///trade.PositionClose(ticket); //---///if(type==POSITION_TYPE_SELL && signal==SIGNAL_BULL)///trade.PositionClose(ticket);
}
It counts the opening and closing of a losing trade as two losses.
i want it to change like 0.1 to 0.2 to 0.4 to 0.8 not 0.1 to 0.2 to 0.3 to 0.4. In some words i want if i lose a trade the next trade try to minimize the days lose to 0. thats why i want to double the lot so that if i win the next trade i will cover the previous los. for example in a 3 losestreak i would have lost 30$ lets say with 0.1 lot first trade and always 5pips sl tp. first lost trade -5 second -10 third -15 so the fourth trade would be or +30 or -30
Also a maximum number of dayly trades to 4 so i thought of adding one extra parametre in the IF statements: i choosed losses<8 instead of losses<4 since you told me every loss counts for 2.
i tried to combine the code you learned me with the one in the example. That is my try. i Hope i am in a good way.
Thank's for the teaching!
I really appreciate it.
1. Please insert the code correctly: when editing a message, press the button
and paste your code into the pop-up window. (The first time I corrected your message)
2. Now we need the next step: state what we are looking for: the last three deals?
1. Please insert the code correctly: when editing a message, press the button and paste your code into the pop-up window. (The first time I corrected your message)
2. Now we need the next step: state what we are looking for: the last three deals?
so i need to change the function
to
so that we take only the last 3 deals? and then modify my last if LIKE
so that i can count and check if there is a losestreak?
I am a bit confused. Thats where i exactly losing control.
1. Please insert the code correctly: when editing a message, press the button and paste your code into the pop-up window. (The first time I corrected your message)
2. Now we need the next step: state what we are looking for: the last three deals?
so this is my whole try makking it work. but it doesnt. any help will be aprecciated
Suggestion: Create functions to make analysing and editing the code easier.
Suggestion: Create functions to make analysing and editing the code easier.
thnx for your reply. i am trying to find out a way to make it work since you commented till now.The things that are missing are:
1)look back to the current days history and count losestreak
2)set up the lotsize of the bet depends on the losestreak that we have
3)if we win dont trade until next day at 9:00 in the morning
4)i want to make it trade only in the candle opening because if it is in atrade that it hits tp or sl and previous candle gives trade signal it takes the trade and thats not very profitable as i have checked it manually during the last months.
Thank's for your time.
Really appreciate it!
Here is my code:
thnx for your reply. i am trying to find out a way to make it work since you commented till now.The things that are missing are:
1)look back to the current days history and count losestreak
2)set up the lotsize of the bet depends on the losestreak that we have
3)if we win dont trade until next day at 9:00 in the morning
4)i want to make it trade only in the candle opening because if it is in atrade that it hits tp or sl and previous candle gives trade signal it takes the trade and thats not very profitable as i have checked it manually during the last months.
Thank's for your time.
Really appreciate it!
Here is my code:
The EA attached to the previous post does all of that ?!
The EA attached to the previous post does all of that ?!
ok i made some changes that i needed and the program it seems to be working perfectly. Buy i have one question. Can you explain me why the lot size is going from 0.1 to 0.3 to 0.5 instead of 0.1 to 0.2 to 0.4?
i am trying to make it increase 0.1 each time for the losestreak.
the thing that i changed is the lotsize=0.1 from 0.2 in your programm and i added sl tp + that i dont want the position to close if another signal appears.
It counts the opening and closing of a losing trade as two losses.
It counts the opening and closing of a losing trade as two losses.
i want it to change like 0.1 to 0.2 to 0.4 to 0.8 not 0.1 to 0.2 to 0.3 to 0.4. In some words i want if i lose a trade the next trade try to minimize the days lose to 0. thats why i want to double the lot so that if i win the next trade i will cover the previous los. for example in a 3 losestreak i would have lost 30$ lets say with 0.1 lot first trade and always 5pips sl tp. first lost trade -5 second -10 third -15 so the fourth trade would be or +30 or -30
Also a maximum number of dayly trades to 4 so i thought of adding one extra parametre in the IF statements: i choosed losses<8 instead of losses<4 since you told me every loss counts for 2.
is that correct?