Basic help please

Post Reply
censura
Trader
Posts: 32
Joined: Wed Jun 06, 2012 12:52 pm

Basic help please

Post by censura »

I am trying to use the Daily Pivot (DP) as a stoploss in the ea i am developing. So far I have used a fixed stoploss (LossLimit) and take profit(ProfitMade) and it is trading fine. I want to test using the DP as the stop loss.

I get the distance values of current price from DP from a DWMP 10.3 10.4 indicator via global variables

But when I try and use this code to set the TP it keeps posting 0.000.

Help would be appritiated

Thank you

Code
if(LossLimit==0 && ProfitMade==0) break;
double stop1 = MathAbs(GlobalVariableGet(Symbol()+"distance"));
// this are values taken from DWMP 10.3 10.4 indicator //

if (stop1 < 15 ) stop1 = 15;


SL=stop1;
if(ProfitMade ==0) TP=0;
SL=Bid-((LossLimit)*myPoint );
if(ProfitMade >0) TP=Ask+((ProfitMade)*myPoint );
OrderModify(ticket,OrderOpenPrice(),SL,TP,0,White);
gle=GetLastError();

if(gle==0)
{
logwrite(TradeComment,"BUY MODIFIED Ticket="+ticket+" Ask="+Ask+" Lots="+lotsi+" SL="+SL+" TP="+TP);TradeAllowed=false;
break;
}
else
{
logwrite(TradeComment,"-----ERROR----- Modifying BUY order: Lots="+lotsi+" SL="+SL+" TP="+TP+" Bid="+Bid+" Ask="+Ask+" ticket="+ticket+" Err="+gle+" "+ErrorDescription(gle));

RefreshRates();
Sleep(500);

loopcount++;
if(loopcount>maxloop)
{
logwrite(TradeComment,"-----ERROR----- Giving up on modifying BUY order");
return(gle);
}
}
}//while - modify order

Sleep(1800000);
}//BUYme
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: Basic help please

Post by gaheitman »

In your code, you aren't actually using the stop1 value to calculate SL. Your initial assignment

Code: Select all

SL=stop1;
is overwritten by

Code: Select all

SL=Bid-((LossLimit)*myPoint );
George
garyfritz

Re: Basic help please

Post by garyfritz »

censura wrote:But when I try and use this code to set the TP it keeps posting 0.000.
Are you sure ProfitMade is > 0? If ProfitMade == 0, TP will be 0.00 ...
Post Reply

Return to “Coders Hangout”