I have written a code in which the buy/sell signals are calculated based on the prices of VXX.
When a buy/sell signal is given, I don’t want to buy VXX but buy another stock (SVXY or SPY).
I can get the prices of both stocks in EXPLORE but not in the BACKTEST …
I have tried to use the Foreign function, but it did not help.
Thanks for your input, but I still have not reached the code I wanted originally.
The system works like this: All buy/sell/short/cover signals are derived from the price action of VXX.
When a buy signal is generated I want the system to buy VXX at the open.
When a sell signal is generated I want the system to sell VXX at the open.
When a short signal is generated I want the system to buy SVXY at the open
When a cover signal is generated I want the system to sell SVXY at the open.
Below you can find the system code as I have it now (only applicable on VXX):
//Initial Parameters
SetOption( "InitialEquity", 50000);
SetPositionSize(100, spsPercentOfEquity);
SetOption("CommissionMode", 1); // percent
SetOption("CommissionAmount", 0.1); //
SetOption ("AllowSamebarExit", 0);
SetTradeDelays (1, 1, 1, 1);
BuyPrice = Open;
SellPrice = Open;
ShortPrice = Open;
CoverPrice = Open;
//Trading Code
Buy = Cross (C, BBandTop (C, 20, 2));
Sell = C > O;
Short = C < MA (C,20) AND C > Ref (C, -1);
Cover = Cross (C, MA (C, 20));
ApplyStop (stopTypeNBar, stopModeBars, Optimize( "max. days",4,3,9,1));
MinHoldBars = 2;
Buy = Buy AND Status("barinrange");
BarsInTrade = 0;
for( i = 0; i < BarCount; i++ )
{
// if in-trade, then increase bar counter
if( BarsInTrade > 0 ) BarsInTrade ++;
else
if( Buy[ i ] ) BarsInTrade = 1; // on buy signal start counting bars-in-trade
// if we are in trade - remove sells occurring too soon
if( BarsInTrade < MinHoldBars ) Sell[ i ] = 0;
else
if( Sell[ i ] ) BarsInTrade = 0; // on sell reset barsintrade flag
}
printf("barsintrade:\n");
WriteVal(barsintrade);
Ok, I finally managed to find the solution on my own thanks to the references to the Foreign () and Name() functions. For those interested, in the code below you can find the solution to my original problem stated in this thread:
Good job by myself that I did not respond on this anymore.
Ask yourself why no one has responded to you anymore for weeks.
The reason is that your posts have been big time wasters.
Why?
Here is why...
You said this one in your first post (Please read loudly and clearly to yourself):
Pay very special attention to
don't
So since you didn't want to buy VXX I have made two examples which exactly do that!
Then all of the sudden you say completely contradicting words
If you are a comedian then that has been worst comedy ever so far in this forum.
(As aside your most recent code did not even have any short signals anymore)
Hopefully your next thread will be better (everyone deserves second chance)...
BTW, if the world would be a cartoon (and after reading your post of 12 days ago)...
@ fxshrat: thanks for your input anyway.
I realize it might have been a stupid question for you, but for me as a beginner it took a while to get it done. I tried it with your proposed solution, but it did not get me to the result I needed. It was only after I started using the Name() functions I got to the solution.