[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SetVar problem



PureBytes Links

Trading Reference Links


Hello,
 
The message "SetVar not successful" is 
displayed
when the type mismatch occur when 
trying
to assign a value to the AFL variable fromthe 
scripting
side.
 
The fix to your formula is simple: don't use 
ReDim()
to size a CPP array. The easiest and quickest 

way to get a new array with correct size and type 

without the need to do Dim() <FONT 
face=Arial size=2>is to make a copy of an existing array.
 
A corrected code of your formula is shown 
below.
 
Best regards,
Tomasz Janeczko
amibroker.com
 
 
/* TS TEST */
 
EnableScript("VBScript");buy = cross(macd(), 
0);LastBuy  = BarsSince(buy);sell = IIF(LastBuy, cross ( 0, 
macd()), 0);
 
buy = exrem( buy, sell);sell = exrem (sell, 
buy);
 
Position = iif(buy, 1, iif( sell, -1, 
0));BuyPrice = ValueWhen( buy, C, 1);SellPrice = ValueWhen( sell, C, 
1);
 
/* PositionProfit = IIF( Sell, SellPrice- 
BuyPrice, 0); *//* Does not seams to work */PositionProfit = IIF(Sell, 
SellPrice - BuyPrice, 0);ProfitRatio = IIF(Sell, SellPrice  /  
BuyPrice, 0);LastSell = BarsSince(Sell);
 
<%PP = AFL.Var("ProfitRatio")CPP = 
PPCPP(0) = 0For i = 1 to Ubound(PP) CPP(i) = ( PP(i)* PP(i-1) 
-1 ) *100Next AFL.Var("CompPercentProfit") = CPP%>
 
ETop = Highest(CompPercentProfit);TopBar = 
HighestBars(CompPercentProfit);
 
<BLOCKQUOTE dir=ltr 
>
<A 
href="">