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
this is my latest code. cant think of anything wrong except it is not giving me the results i want
//+------------------------------------------------------------------+ //| RSI_strategy_cyxstudio.mq4 | //| Copyright 2013, Tjipke de Vries | //| https://forum.mql4.com/53695/ | //+------------------------------------------------------------------+ #property copyright "Copyright 2013, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #include <stderror.mqh> #include <stdlib.mqh> extern int RSIPeriod = 2; //number of periods for RSI extern double UpperBound = 95; //set upper bound value for RSI extern double LowerBound = 5; //set lower bound value for RSI extern double Lots = 0.1; extern double StopLoss = 60; //Set the stop loss level extern double TakeProfit = 120; //Set the take profit level extern double TrailingStop = 40; //extra settings for OrderSend extern int MagicNumber = 54333; extern string CommentEA = "RSI strategy"; extern int Slippage.Pips = 3; //--- //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- Alert(OrdersTotal()); //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- int Ticket1; int Ticket2; bool Ticket3; bool Ticket4; double SL,TP; int Total; double MagicNo; double Slippage; int cnt; double pAsk = MarketInfo(Symbol(), MODE_ASK); double pBid = MarketInfo(Symbol(), MODE_BID); double MA200 = iMA(NULL, 1440, 200, 0,MODE_SMA,PRICE_CLOSE, 0); //200 day Moving Average double MA5 = iMA(NULL, 1440, 5, 0,MODE_SMA,PRICE_CLOSE, 0); // 5 day Moving Average double CurrentRSI = iRSI (NULL, 0, RSIPeriod,PRICE_CLOSE ,0); double PrevRSI = iRSI (NULL, 0, RSIPeriod,PRICE_CLOSE ,1); double LastRSI = iRSI (NULL, 0, RSIPeriod,PRICE_CLOSE ,2); if(Bars<100) { Print("bars less than 100"); return(0); } if(AccountFreeMargin()<(1000*Lots)) { Print("We have no money. Free Margin = ", AccountFreeMargin()); return(0); } //Check for open orders if there are none then check for conditions to open one if (OrdersTotal() ==0 && LastRSI > PrevRSI && PrevRSI > CurrentRSI && CurrentRSI < LowerBound && pAsk > MA200) { //Condition to execute buy entry Ticket1 = OrderSend(Symbol(), OP_BUY, Lots, pAsk, Slippage.Pips, pBid - ( StopLoss * Point ), pAsk + ( TakeProfit * Point ), "Buy.", MagicNumber,0,Yellow); //execute buy order if(Ticket1>0) { if(OrderSelect(Ticket1,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } if (Ticket1 < 0) { Print("Error opening BUY order : ",GetLastError()); return(0); } if (OrdersTotal() ==0 && LastRSI < PrevRSI && PrevRSI < CurrentRSI && CurrentRSI > UpperBound && pBid < MA200) { //Condition to execute sell entry Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, pBid, Slippage.Pips, pAsk + ( StopLoss * Point ), pBid - ( TakeProfit * Point ), "Sell.",MagicNumber, 0, Yellow) ; //execute sell order if(Ticket2>0) { if(OrderSelect(Ticket2,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } if (Ticket2<0) { Print("Error opening SELL order : ",GetLastError()); return(0); } } } int ticket=OrderTicket(); double lots=OrderLots(); for (int i = OrdersTotal() - 1; i >= 0; i--) { if (OrderSelect(i, SELECT_BY_POS)) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_BUY && pBid > MA5) { Ticket3 = OrderClose(ticket, lots, pBid, Slippage.Pips); if (Ticket3 == true ) { Print("BUY position closed", OrderClosePrice()); } if (Ticket3 == false) { Print("Error closing BUY position", ErrorDescription(GetLastError())); } } if (OrderType() == OP_SELL && pBid < MA5) { Ticket4 = OrderClose(ticket, lots, pAsk, Slippage.Pips); if (Ticket4 == true ) { Print("SELL position closed", OrderClosePrice()); } if (Ticket4 == false) { Print("Error closing SELL position", ErrorDescription(GetLastError())); } } } } } return(0); }If you look at page 2 this topic you can find what I gave you
This is the begin.....
Give your comment ..... about what is different from yours so far...
Then take a read at https://www.mql5.com/en/forum/139654 and try to make a loop counting down checking trades
As you can see I asked to make a loop counting down checking trades
That is my next step inside the code
I only ask you for that part of code
make it count buy trades and sell trades separetly
If you look at page 2 this topic you can find what I gave you
i removed it because i didnt know how to use it. you gave me the code partially i couldnt see how it functions.
--
This is the begin.....
Give your comment ..... about what is different from yours so far...
Then take a read at https://www.mql5.com/en/forum/139654 and try to make a loop counting down checking trades
As you can see I asked to make a loop counting down checking trades
That is my next step inside the code
I only ask you for that part of code
make it count buy trades and sell trades separetly
like this?
int ticket=OrderTicket();//blocks of codes to execute
}
i removed it because i didnt know how to use it. you gave me the code partially i couldnt see how it functions.
The moment The EA starts again
BUYS is set to 1
SELLS is set to 1
OrdersTotal() is giving total of all open trades on your account
It can be zero then we have notrades open and we don't need to check if there are trades of this EA
If OrdersTotal() > 0 BUYS stays 1 and SELLS Stays 1
we need to check in that case if it is from our EA and we have to count the different types (buy,sell,buylimit....)
so
like this?
int ticket=OrderTicket();//blocks of codes to execute
}
Use SRC Button
This loop we only start ( for what condition )
How do you know the selected trade in the loop is buy or sell??
And how do you count them ??
Use SRC Button
This loop we only start ( for what condition )
How do you know the selected trade in the loop is buy or sell??
And how do you count them ??
opps.
if (OrderType() == OP_BUY && pBid > MA5) { Ticket3 = OrderClose(ticket, lots, pBid, Slippage.Pips); if (Ticket3 == true ) { Print("BUY position closed", OrderClosePrice()); } if (Ticket3 == false) { Print("Error closing BUY position", ErrorDescription(GetLastError())); } } if (OrderType() == OP_SELL && pBid < MA5) { Ticket4 = OrderClose(ticket, lots, pAsk, Slippage.Pips); if (Ticket4 == true ) { Print("SELL position closed", OrderClosePrice()); } if (Ticket4 == false) { Print("Error closing SELL position", ErrorDescription(GetLastError())); } } }for the closed trade function.
using
if (OrderType() == OP_SELL && pBid < MA5)to differentiate buy and sell.
is there anything wrong with my conditions to open order?
shud i remove it and replace with the loop i used for close order function?
opps.
for the closed trade function.
using
to differentiate buy and sell.
is there anything wrong with my conditions to open order?
shud i remove it and replace with the loop i used for close order function?
At this moment you have to check if there is already a trade open
before you open a trade you have to know if there is a trade open
still I can't see you have done the counting of trades
.
Take a look at the code of the Moving Average EA on your metatrader Station and see how it is done there ....