Coding the takeprofit/stoploss

 

Hey everyone,

I need to add the take profit level in the code because it stops me at 5 pips max when i actually want to do 3 pips take profit (3 normal + 2 spread) I'd like to code it within so I don't get stopped by the program.

If anyone could help me that would be great, I have the code already here online,

https://www.mql5.com/go?link=http://forex1000.com/cnet/CCI-volatile.mql

if you just have a clip of the code could you tell me where to put it (either anywhere or beginning or end, etc., etc., etc.)

Thanks alot in advance

 

Gazuz, let's fix the expert first. BelowPrevious2 and AbovePrevious2 are dummy variables (no value assigned to it). What are these two variables supposed to do here?

 

Oh I actually had another strategy planned with it, they were used before, they have no more use now. The expert is suppose to open a maximum of 1 trade per candle (even if the CCI indicator crosses back the 0 line). Also I want it to open the trade right when it crosses, not at the next candle.

 

what should i do after this?

 

Here's you go with virtual SL extra:


/*[[ Name := Gazuz CCI v2.1
Author := strategy from Gazuz, first coded by David, re-coded by Scorpion.
Link :=
Enable Alerts := Yes
Lots := 2.00
Stop Loss := 50
Take Profit := 5
Trailing Stop := 0
]]*/

Defines : slippage(4),CCI_Period(50),Buy_Cross_Point(1),Sell_Cross_Point(-1);
Defines : VirtualTP(5),VirtualSL(0);
Variable : SignalStrength(0);
Variable : cnt(0),i(0);
Variable : CurrentCCI(0),AboveCurrent(0),BelowCurrent(0),AbovePrevious(0),BelowPrevious(0),BelowPrevious2(0),AbovePrevious2(0),;
Variable : vSL(0),vTP(0),IsvSLTPHit(False);

CurrentCCI=iCCI(CCI_Period,0);
AboveCurrent = (CurrentCCI > (Buy_Cross_Point));
AbovePrevious = (iCCI(CCI_Period,1) > (Sell_Cross_Point));
BelowCurrent = (CurrentCCI < (Sell_Cross_Point));
BelowPrevious = (iCCI(CCI_Period,1) < (Buy_Cross_Point));

if abs(CurrentCCI)<200 then
{
SignalStrength=100-(abs(CurrentCCI)/2);
}
else
{
SignalStrength=0;
};

Comment("Signal's Strength: ",SignalStrength,"%");


For cnt=1 to TotalTrades
{
If Ord(cnt,VAL_SYMBOL)=Symbol and Ord(cnt,VAL_TYPE)=OP_BUY Then
{
IsvSLTPHit = (Bid 0) or (Bid >= vTP and vTP > 0);
If ((AbovePrevious2) and (BelowPrevious) and (BelowCurrent)) or IsvSLTPHit Then
{
CloseOrder(OrderValue(cnt,VAL_TICKET),
OrderValue(cnt,VAL_LOTS),
OrderValue(cnt,VAL_CLOSEPRICE),
0,
White);
vSL=0;
vTP=0;
Alert("CCI Expert Closed Buy Trade",".",Symbol);
Exit;
};
};

If Ord(cnt,VAL_SYMBOL)=Symbol and OrderValue(cnt,VAL_TYPE)=OP_SELL Then
{
IsvSLTPHit = (Bid >= vSL and vSL > 0) or (Bid 0);
If ((BelowPrevious2) and (AbovePrevious) and (AboveCurrent)) or IsvSLTPHit Then
{
CloseOrder(Ord(cnt,VAL_TICKET),
Ord(cnt,VAL_LOTS),
Ord(cnt,VAL_CLOSEPRICE),
0,
Gold);
vSL=0;
vTP=0;
Alert("CCI Expert Closed Sell Trade",".",Symbol);
Exit;
};
};
};


If TotalTrades < 1 And Volume < 10 Then
{
If (AbovePrevious) and (BelowCurrent) Then
{
vTP=Bid-(VirtualTP*Point);
vSL=Bid+(VirtualSL*Point);
SetOrder(OP_SELL,
Lots,
bid,
slippage,
bid+StopLoss*Point,
bid-TakeProfit*Point,
Gold);
Alert("CCI Expert Opened a Sell Trade",".",Symbol);
Exit;
};

If (BelowPrevious) and (AboveCurrent) Then
{
vTP=Bid+(VirtualTP*Point);
vSL=Bid-(VirtualSL*Point);
SetOrder(OP_BUY,
Lots,
ask,
slippage,
ask-StopLoss*Point,
ask+TakeProfit*Point,
white);
Alert("CCI Expert Opened a Buy Trade",".",Symbol);
Exit;
};
};

For i=1 to TotalTrades
{
If TrailingStop<5 Then
{
print("Invalid trailing stop");
Exit;
};

If Ord(i,VAL_SYMBOL)=Symbol and Ord(i,VAL_TYPE)=OP_BUY Then
{
If (Bid-Ord(i,VAL_OPENPRICE))>(TrailingStop*Point) Then
{
If Ord(i,VAL_STOPLOSS)<(Bid-TrailingStop*Point) Then
{
ModifyOrder(Ord(i,VAL_TICKET),
Ord(i,VAL_OPENPRICE),
Bid-TrailingStop*Point,
Ord(i,VAL_TAKEPROFIT),
White);
};
};
};

If Ord(i,VAL_SYMBOL)=Symbol and Ord(i,VAL_TYPE)=OP_SELL Then
{
If (Ord(i,VAL_OPENPRICE)-Ask)>(TrailingStop*Point) Then
{
If Ord(i,VAL_STOPLOSS)>(Ask+TrailingStop*Point) Or Ord(i,VAL_STOPLOSS)=0 Then
{
ModifyOrder(Ord(i,VAL_TICKET),
Ord(i,VAL_OPENPRICE),
Ask+TrailingStop*Point,
Ord(i,VAL_TAKEPROFIT),
Gold);
Exit;
};
};
};
};

//------------- t_David

 

hi,

my question may sound stupid,but thatz how everyone learns!!!!!!!!

how to use this ea code with any trading platform.please gimme step by step instructions.Will be a gr.....eat help.

Reason: