I want to have a Profit Stop sell at a certain time if the profit 
stop is met. 

I was using the close, but the bar doesn't always close at the same 
time. So I tried to use this. 


"LastP = "+GetRTData("Ask"); 

if( ProfitTarget ) // allows taking a profit any time
{
        if( DebugOn AND numPositions != 0 ) _TRACE("#, Profit Stop is 
on. TradePrice=" + NumToStr(TradePrice, 1.3) +  
                ", Close=" + NumToStr(LastC, 1.3) + ", ProfitVal=" + 
NumToStr(ProfitVal, 1.2) + "\n");
        if(numPositions > 0 )
        {
                ProfitStopValue = TradePrice + profitVal;
                // note that SellTrigger is also set by trailing stop
                if(LastP >= ProfitStopValue AND hourTrigger)    
                {
                        ProfitStop = 1;         // used to generate a 
sell signal when profit target is reached
                        fSayOnce("profit sell");
                }
                profitDelta = 100 * (ProfitStopValue - LastC); // 
calculates the distance to the stop, when 0 the target has been 
reached
                if(DebugOn)     _TRACE("#, ProfitStop 2, Stop value=" 
+ NumToStr(ProfitStopValue, 1.2) + 
                        ", ProfitDelta=" + NumToStr(profitDelta, 1.2) 
+ "\n");
        }
        else if(numPositions < 0)
        {
                ProfitStopValue = TradePrice - profitVal;
                if(ProfitStopValue >= LastC) 
                {
                        ProfitStop = 2;         // used to generate a 
cover signal when profit target is reached      
                        fSayOnce("profit cover");
                }
                profitDelta = 100 * (LastC - ProfitStopValue);  // 
calculates the distance to the stop, when 0 the target has been 
reached
                if(DebugOn)     _TRACE("#, ProfitStop 3, Stop value=" 
+ NumToStr(ProfitStopValue, 1.2) +  
                        ", ProfitDelta=" + NumToStr( profitDelta, 
1.2) +  "\n");
        }
}
else
{
        if(DebugOn)     _TRACE("#, Profit Stop is off." + "\n"); 
}
        
When I verify this, I don't get any errors. However when I use it in 
my chart everything is fine until I turn the profit stop on in my 
parameters, then I get this error.


Error 29.
Variable 'lastp' used without having been initialized.

What am I doing wrong?

Thanks,
Tom

Reply via email to