15112020:
How do I correct my possible loss of data due to type conversion?
. . .
Boa tarde!
Erro de compilação resolvido:
#property strict #include<Trade/trade.mqh> CTrade trade; CPositionInfo pos; int myRSIDefinition; int k; double currRSI; void CloseBuyPositions(){ //count down till are no positions left for(int i=PositionsTotal()-1; i>=0; i--){ //Get the ticket number for the current postion //int ticket=PositionGetTicket(i); ulong ticket=PositionGetTicket(i); //Get the position direction //int PositionDirection=PositionGetInteger(POSITION_TYPE); long PositionDirection=PositionGetInteger(POSITION_TYPE); //if it is a buy position if(PositionDirection==POSITION_TYPE_BUY){ trade.PositionClose(ticket); } }//end of loop }//end of function void CloseSellPositions(){ //count down till are no positions left for(int i=PositionsTotal()-1; i>=0; i--){ //Get the ticket number for the current postion //int ticket=PositionGetTicket(i); ulong ticket=PositionGetTicket(i); //Get the position direction //int PositionDirection=PositionGetInteger(POSITION_TYPE); long PositionDirection=PositionGetInteger(POSITION_TYPE); //if it is a buy position if(PositionDirection==POSITION_TYPE_SELL){ trade.PositionClose(ticket); } }//end of loop }//end of function int OnInit() { //defining the properties of the RSI myRSIDefinition = iRSI(_Symbol, _Period, 14, PRICE_CLOSE); return(INIT_SUCCEEDED); } void OnTick() { //creating an array for several prices double myRSIArray[]; //sorting the price array from the current candle downwards ArraySetAsSeries(myRSIArray,true); //defined EA, current candle, 3 candles, store result CopyBuffer(myRSIDefinition, 0, 0, 3, myRSIArray); //calculating RSI for the current candle double myRSIValue= NormalizeDouble(myRSIArray[0],2); //it attributes the current RSI tick value to the previous one double prevRSI = currRSI; //it attributes the current tick RSI value to the variable currRSI currRSI = myRSIValue; //if the position of the current currency pair has a open buy order then it attributes 1 to k, if not, 2 to k if(PositionSelect(_Symbol)==true && pos.PositionType()==POSITION_TYPE_BUY){ k=1; }else{ k=2; } //if the previous tick RSI value is greater and equal than 70 and the current tick RSI value below 70, then the EA opens a short trade if(k==1 && PositionsTotal() == 1 && prevRSI>=70 && currRSI<70) { double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID),_Digits); double Balance= AccountInfoDouble(ACCOUNT_BALANCE); double Equity= AccountInfoDouble(ACCOUNT_EQUITY); trade.Sell(0.05, NULL, 0,0,(0), NULL); CloseBuyPositions(); }else if(k==2 && PositionsTotal() == 1 && prevRSI<70 && currRSI>=70){ //if the previous tick RSI value is below 70 and the current tick RSI value is greater or equal than 70, then the EA opens a long trade double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK),_Digits); double Balance= AccountInfoDouble(ACCOUNT_BALANCE); double Equity= AccountInfoDouble(ACCOUNT_EQUITY); trade.Buy(0.05, NULL, 0,0,(0), NULL); CloseSellPositions(); }else if(PositionsTotal() ==0 && prevRSI>=70 && currRSI<70 ){ double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID),_Digits); double Balance= AccountInfoDouble(ACCOUNT_BALANCE); double Equity= AccountInfoDouble(ACCOUNT_EQUITY); trade.Sell(0.05, NULL, 0,0,(0), NULL); }else if(PositionsTotal()==0 && prevRSI<70 && currRSI>=70){ double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK),_Digits); double Balance= AccountInfoDouble(ACCOUNT_BALANCE); double Equity= AccountInfoDouble(ACCOUNT_EQUITY); trade.Buy(0.05, NULL, 0,0,(0), NULL); } Comment("prevRSI: ",prevRSI, " currRSI: ", currRSI); }
Vinicius de Oliveira:
Boa tarde!
Erro de compilação resolvido:
Obrigado irmão.
Eu tenho um problema de logística mas acho que você não viu ou leu. O meu EA não fecha a trade anterior quando abre uma nova. Eu adicionei if's e as funções CloseSellPositions() e CloseBuyPositions() mas continua não funcionando. Desculpa se demorei responde. Só vi hoje a resposta, e tenho estado ocupado.
Muito obrigado mesmo.

Você está perdendo oportunidades de negociação:
- Aplicativos de negociação gratuitos
- 8 000+ sinais para cópia
- Notícias econômicas para análise dos mercados financeiros
Registro
Login
Você concorda com a política do site e com os termos de uso
Se você não tem uma conta, por favor registre-se
My EA is supposed to open a long trade when a cross from below the RSI value 70 happens and to open a short trade if a upcross of the RSI value 70 happens too. For example: if a upcross happens, and there's already an open long trade he opens a short trade after closing the long trade. It goes both ways. BUT it isn't closing the previous trade(this is what I want the EA to do but it doesn't do). When I compile the archive, these warnings show up:
possible loss of data due to type conversion roboRSIRSI.mq5 line 15 column 17
possible loss of data due to type conversion roboRSIRSI.mq5 line 18 column 28
possible loss of data due to type conversion roboRSIRSI.mq5 line 34 column 17
possible loss of data due to type conversion roboRSIRSI.mq5 line 37 column 28
Ah, if there aren't any trades open he just adds a short trade in case of a upcross or a long trade in case of a below cross.
I tried everything from adding more if's to changing values to see where did I do wrong, but it keeps doing the same thing. Thanks to those who can help.
Here is my code: