help to convert from MQL to MQL4

 

Hi all,

appreciate if someone can help me to convert to MQL4. below is the code:-

/*---------------------------------------------------------------------------------------------------------*\
//
// This MQL is a test for me to auto generate position on RSI reading value
//
// The Logic for reference : OB 82 SELL position TP 15-20Pips(need to built *.dll for variables)
// OS 18 BUY position TP 15-20pips(")
// TF to use TF 5 min (") however records shows tht it can be use in TF15/30MinS.
// SL TP number of LOT and price per lot need variable in *.dll
// PAIR - ALL PAIR. But Aim for low SPREAD PAIR.
// The real strategy is open post at variable setting but the positions can be optimised to optimised profit
// this is only optional if can be coded whenever the countered RSI reading >1 from variables to another digit.
// OS 18/17/16 and OB 82/83/84
//( recors shows its happen during NFP or high FA effect. The TP shud be at the 1st open position.
//However, records also shows
// tht if this happen than the reverse pips is up to 50 or 80 pips(GU 100pips-150 pips during NFP).
//Therefore the trailing stp is usefull if higher TP is put into the variables.
//
// The biggest problem - time beig I do not know how to convert into MQL to MQ4 and built DLL and compile this.
// The ASCII looks like so complecated
//*-----------------------------------PLEASE DO NOT REMOVE THIS HEADER--------------------------------------*/
/*[[
Name := RSI_Pipscatch
Author := kotabelud

Lots := 2
Stop Loss := 50
Take Profit := 20
Trailing Stop := 10
]]*/
defines: Slippage(3);
defines: ;
var: cnt(0),IsBuying(False),IsSelling(False),IsClosing(False),RealTP(0),RealSL(0);
var: rsi1_1(0),rsi1_0(0);

// Check for invalid bars and takeprofit
If Bars<200 then Exit;

// Calculate indicators' value
rsi1_1 = iRSI(14,1);
rsi1_0 = iRSI(14,0);


// Check for BUY, SELL, and CLOSE signal
IsBuying = (rsi1_0 == 180000);
IsSelling = (rsi1_0 == 820000);
IsClosing = False;

// Control open trades
for cnt=1 to TotalTrades
{
// Control only market trades not entry order
if OrderValue(cnt,VAL_TYPE)<=OP_SELL and
OrderValue(cnt,VAL_SYMBOL)=Symbol then
{

// Check for close signal for bought trade
If OrderValue(cnt,VAL_TYPE)=OP_BUY then
{

If IsSelling or IsClosing then
{
// Close bought trade
CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,3,Violet);
Alert("RSI_PipsHunter: Closing BUY order.");
};

// Check trailing stop
If TrailingStop>0 then
{
If (Bid-OrderValue(cnt,VAL_OPENPRICE))>(Point*TrailingStop) then
{
If OrderValue(cnt,VAL_STOPLOSS)<(Bid-Point*TrailingStop) then
{
// Modify trailing stop
ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),
Bid-Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Red);
};
};
};
}
else
{

// Check sold trade for close signal
If IsBuying or IsClosing then
{
CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Ask,3,Violet);
Alert("RSI_PipsHunter: Closing SELL order.");
};

// Control trailing stop
If TrailingStop>0 then
{
If (OrderValue(cnt,VAL_OPENPRICE)-Ask)>(Point*TrailingStop) then
{
If OrderValue(cnt,VAL_STOPLOSS)=0 or
OrderValue(cnt,VAL_STOPLOSS)>(Ask+Point*TrailingStop) then
{
ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),
Ask+Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Red);
};
};
};
};
};
};


// If there is no open trade
If TotalTrades<1 then
{
// If we have enough money for 1 lot
If FreeMargin<1000 then Exit;

// Check for BUY entry signal
If IsBuying and IsSelling=False and IsClosing=False then
{
// Buy
If StopLoss>0 then
{
RealSL=Ask-StopLoss*Point;
}
If TakeProfit>0 then
{
RealTP=Ask+TakeProfit*Point;
}
SetOrder(OP_BUY,Lots,Ask, Slippage,RealSL,RealTP,RED);
Alert("RSI_PipsHunter: Buying");
};

// Check for SELL entry signal
If IsSelling and IsBuying=False and IsClosing=False then
{
// Sell
If StopLoss>0 then
{
RealSL=Bid+StopLoss*Point;
}
If TakeProfit>0 then
{
RealTP=Bid-TakeProfit*Point;
}
SetOrder(OP_SELL,Lots,Bid,Slippage,RealSL,RealTP,RED);
Alert("RSI_PipsHunter: Selling");
};
};


//-------------- Pipscatch

regards

kotabelud

Reason: