Problem with SellPrice

I have a problem overriding the SellPrice in the AFL code.
I can overwrite the BuyPrice in the AFL code.

I use the following settings:

SetBacktestMode( backtestRegular );
SetOption("InitialEquity", AnfangsKapital); 
SetOption("FuturesMode", False);
SetOption("MaxOpenPositions",MaxPos);
SetOption("AllowPositionShrinking",true);
SetOption("AllowSameBarExit",true);
SetOption("DisableRuinStop", True);
SetOption("CommissionMode",1);
SetOption("CommissionAmount",0.06);
RoundLotSize = 1; 
SetOption("NoDefaultColumns", True );
SetOption("UsePrevBarEquityForPosSizing", False);
SetTradeDelays (0, 0, 0, 0);
BuyPrice = ShortPrice = Open;
SellPrice = CoverPrice = Open;

For example, if I change the code as follows:

BuyPrice = ShortPrice = Open;
SellPrice = CoverPrice = Close;

The open price will continue to be used in the backtest. Even a change in the Automatic Analysis Window does not change the backtest. I don't use ApplyStop...

I've read many comments in the forum about "SellPrice" but haven't been able to find a solution so far.

It would be great if someone could help me

@jerdchen, I tried your posted code (defining the missing variables) and everything seems to work as expected.

I used the snippet:

BuyPrice = ShortPrice = Open;
SellPrice = CoverPrice = Close;

(adding the EMA crossover trading rules snippet, as provided as an example by Amibroker).

image

I suggest to double check the results comparing the data with the Quote Editor prices, as I did in the above screenshot.

1 Like

same here. Code works as expected:

SetBacktestMode( backtestRegular );
SetOption("InitialEquity", 100000); 
SetOption("FuturesMode", False);
SetOption("MaxOpenPositions",1);
SetOption("AllowPositionShrinking",true);
SetOption("AllowSameBarExit",true);
SetOption("DisableRuinStop", True);
SetOption("CommissionMode",1);
SetOption("CommissionAmount",0.06);
RoundLotSize = 1; 
SetOption("NoDefaultColumns", True );
SetOption("UsePrevBarEquityForPosSizing", False);
SetTradeDelays (0, 0, 0, 0);
BuyPrice = ShortPrice = Open;
SellPrice = CoverPrice = c;
Buy = Cross(C,MA(C,50));
Sell = Cross(MA(C,50),C);
1 Like

Why do you guys not follow the forum rules and post complete reproducible code !!!

I repeat:

  1. including minimum, but working reproducible example of the formula that shows the problem that can be copy-pasted and run without modification

and

  1. better yet, in case of Analysis (backtest/exploration/optimization), save entire PROJECT FILE (File->Save As...) into .APX file and attach it so one can just load the project (this includes formula and settings)
2 Likes

I compare with Quote Editor ...

with this Code SellPrice is not Close, is Open ...

BuyPrice = ShortPrice = Open;
SellPrice = CoverPrice = Close;

AB_1

But i can Change BuyPrice in Afl Code .... Works ....

BuyPrice = ShortPrice = Close;
SellPrice = CoverPrice = Close;

AB_2

The entire code is many, many hundreds of lines long.

I don't think anyone here would bother with that. Maybe someone has a hint why I can override BuyPrice in AFL and not SellPrice.

Apparently you don't understand a thing.
It is not about hundreds of lines it is about MINIMUM complete code without missing parts that is reproducible. Shrink your code in such a way that it still shows the issue described. I don't think it is that difficult to understand.

Otherwise follow advice here and solve yourself.

2 Likes

First of all, I know how to "debug" a code. This code successfully handles sums in the high seven digits. I think it doesn't take too much thought to understand that I don't want to publish this code here.

My one and only question was why I can override BuyPrice and not SellPrice.

I was just asking if someone could give me a hint as to what could be causing this.

It's actually not difficult to understand, is it???? I don't quite understand your rude answer. I'm friendly too, aren't I???

Then go ahead and debug it!

That's perfectly fine. However you need to follow forum rules and (as @fxshrat as already advised) post reproducible code. Just replace your 'Secret Source' values with dummy values.

You said you know how to debug!

You have been given the appropriate answer but you don't want to listen.

It's yourself who is not understanding.

@fxshrat is not being rude, he is being direct (which is warranted due to your responses).

1 Like

@fxshrat @TrendSurfer @peter1 @beppe

I have to apologize to everyone.
I made the mistake
A really stupid mistake.
So far I have only ever used Open as Enter and Exit and at some point I overwrote the SellPrice in the CBT.

bo.ExitTrade(i, ScaleExit.Symbol, MyTrade.GetPrice(i, "O")); 

So again apologies to all

3 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.