Can't switching between Stock/Future mode



I've designed Future trading system for a very long time.
Today, I want to try new stuffs on Stock mode, unfortunately I can't turn off Future mode.

I tried many ways

  • make sure not to tick anything relate to Future mode
  • set Point value, roundlot size, margin, etc.. to default value (eventhough they're irrevant)

but still i'm stuck in Future mode. Position "Shares" always show in "Contact" style (and affect by "PointValue" and "Initial Margin"

Is this something in my code lock me in this Future mode?
Please help

Thank you,

SetOption( "FuturesMode", False ); // turn OFF futures mode
PointValue = 1;

// and DO NOT set MarginDeposit variable 

Thank you, it's work !

I am having the same issue. I tried Tomasz solution but P&L is still based on the futures contract settings. If I manually change the settings for the symbol to the TickValue to 0 and PointValue to 1 in the symbol information window it will produce the intended results.

How do I get AmiBroker to release the contract settings without manually changing each symbol?



As in previous reply. You need to have PointValue set to 1 and Margin Deposit to zero.

And you don't need to do that manually. The code will do that in a matter of second

I have the same problem, but the other way around!
I did all recommendation, but still cannot switch to future mode!

any suggestion?!

Unfortunately your post does not provide all necessary details to give you an answer. Please follow this advice: How to ask a good question

Whatever you set in the formula overrides settings. It just works. The column name is irrelevant. Futures mode works regardless. In the report it is called "Shares" regardless of mode.

Shares column header in your picture does not mean that you are not in Futures mode (if it is enabled).
It is just header display. Nothing more and nothing less. If futures mode is enabled (as in your picture) then it is futures mode applied.

Status: Shares header display (even though futures mode being enabled).


Now you can get Contracts header display this way:

  1. Save following formula to file (only that one but nothing else)
    Buy = 1;
    Sell = Short = Cover = 0;
  2. Apply it to Analysis (just single analysis window being opened)
  3. Enable futures mode in Analysis setting - General - Futures mode then click OK
  4. Hit Backtest button
  5. Close analysis window after backtest being finished
  6. Close AmiBroker
  7. Restart AmiBroker
  8. Open Analysis window
  9. Run backtest again

Column header will show Contracts now.


If you want to go back to Shares header display then do the same step by step procedure as above but disable Futures mode of point 3.

(Again it is just header display.)

1 Like

That is correct. This column is just "contracts/shares" but it would be too wide to have such long name.

Thanks for swift reply.
I think the problem is that I have different database for Stocks and Forex. When i close and open the Amibroker, it load Stock database and thus setting of that database won't let the Future mode to be applied!

Data base got nothing to do with whether futures mode is enabled or not.
Either future mode setting is enabled or it is not enabled. Simple.

To check whether it is enabled put Trace at end of your code

Buy = 1;
Sell = Short = Cover = 0;

_TRACEF("FUTURES MODE: %g", GetOption("FuturesMode"));

If it returns 1 then it is enabled (no matter which database).
(Still check your code whether you have multiple Setoption("FuturesMode",...) there)


And once again column header showing "Shares" does NOT mean that futures mode is disabled!
So what else makes you think that futures mode is disabled at your end? You speak with mysterious words.

@Oscar - the column header IS IRRELEVANT ! It does NOT indicate the futures mode. It is NOT intended to be changing each time you change the formula. It only changes after application restart as @fxshrat already told you, but still it is irrelevant. Futures mode is on when you turned it on, and it is NOT indicated by column name.

You are making wrong assumption about that column. It has NO assumed meaning. It could be called "number of items" or "qty".

Hi again, thanks for your time and clarification.
In the _TRACEF shows future mode:1, nothing mystery though!


I may be misunderstood! If you check the report, you may see that Amibroker bought 1 lot of in each trade (which should be) and "PositionValue" is not correct of each trade!
This made me hesitate if this might be due to the Future mode problem.

There are NO PROBLEMS in AmiBroker.
The problem is USERS who do not read the manual.

Read it

PositionValue is CORRECT. And Futures mode works 100% fine.

PositionValue in FUTURES mode is the amount of MarginDeposit * Qty (the value that you paid to open position)

Look at that:

MarginDeposit = 5; // the amount you pay in futures mode to open 1 contract pos
SetPositionSize( 1, spsShares );

SetOption("FuturesMode", True );

It will give you position size 5, regardless of security.

1 Like

It is correct calculation (as AB just does what you told it to do) but you are using other settings in undesired way. If you use positive margin deposit such as 1000 (as in your case) then e.g. remove JPY from Information window's Currency field of pair USDJPY.


Otherwise it would divide 1000 Yen (deposit) by USDJPY price to get $9.14 (in your case) as you probably have set similar to below picture of Tools - Preferences - Currencies.


You intend to set $1000 margin deposit per contract but not 1000 Yen.

Proof that AB works properly:

Example USDJPY

$ Margin value (positive value)

//USDJPY example one
Buy = Status("firstbarintest");
Sell = 0;
Short = Cover = 0;

MarginDeposit = 1000;// $ value
PointValue = 100000/Close;

SetOption("InitialEquity", 1000000);
SetPositionSize(1, spsShares);// 1 lot

Remove JPY from Currency field

Result list


Percent margin (negative value)

Buy = Status("firstbarintest");
Sell = 0;
Short = Cover = 0;

MarginDeposit = -1;// percent leverage 100:1
PointValue = 1;

SetOption("InitialEquity", 1000000);
SetPositionSize(100000, spsShares);// 100000 units equal to 1 std. lot

Result list


So in both cases you get same Profit/loss result. Only difference is that in one case it is showing contracts -> 1 lot and in other case 100,000 units (which is equal to 1 lot).

So how is it calculated:

In both cases you bought 100,000 USD at entry price of 113.521
So we bought 100,000 USD and sold 11.3521 million Yen.
Then at exit we sold 100,000 USD for 10.7329 million Yen.
So profit/loss is calculated by 10.7329 - 11.3521 = - 0.6192 (million) Yen = 619,200 Yen
Since we look for dollar loss we divide it by exit price 107.329 and get -5769.177016 Dollar = (rounded) -5769.18.

So all correct and fine.



Hi @fxshrat, thanks for the very informative reply. I appreciate your time and support.
I tried the "Percent margin (negative value)", but didn't get the same value as you did!


I cannot find what error I do that I don't get the same as you did.

In addition, If we want to dynamically calculate the MarginDeposite (as you mentioned in the pdf file you prepared)

// FX Margin account settings ::::::::::::::::::::::::::::::::::
// these settings override settings of "Information" window
TickSize = IIf( StrFind( Name(), "JPY" ), 0.01, 0.0001 );
RoundLotSize = 1;
PointValue = 1;
Leverage = 50; // change to different leverage if using other broker i.e. IAB -> 40
MarginRate = 1 / Leverage;
// dynamic calculation of margin
MarginDeposit = -100 * MarginRate; // here 100*0.02 = 2(%) 1:50
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Required margin deposit should be calculated as below. let's assume that the account currency is USD. for the pairs such as USDCAD or USDCHF, we have:

MarginDeposite = Close × Units × 1/leverage

for the pairs such as AUDUSD or EURUSD, we would have

MarginDeposite = Units × 1/leverage

For the non-major pairs such as EURCAD, we would have:

MarginDeposite = Close × Units × 1/leverage/(Close_USDCAD)

PointValue calculation is also needed to be adjusted based on pairs and cannot be simply "100000/C".
Am I right or not? Please kindly comment if I'm not.
If yes, does your first suggestion calculate the margin deposit in the same way?

In this case, Percent Margin method looks easier to implement. However, PointValue cannot set to one for all pairs.

Be grateful to have your comment.

Be thankful if @fxshrat or anyone can help.
Why I don't get the same reply as what fxshrat?
What about dynamic margin deposit I have explained. How AB calculate the Margin for the non-account currencies (such as AUDCAD with account currency of USD)?


Unknown code and unknown full settings. So it's speculation what you did incorrectly.

But all I know is that I am getting correct results (as usual)!
Using your entry/exit prices

No you are not right.

Your calculations are incorrect.

No. If you buy 100,000 units USDCAD, USDCHF, USDJPY then it is
$100,000 / leverage.

No, when you buy 100,000 AUDUSD, EURUSD then (with account currency USD) it is
100,000 AUD (EUR) / leverage * pair price

No, it is incorrect also. See second example.

But for dynamic margin deposit (percent margin) you just need to set negative value. Nothing more nothing less. Rest is done via Currency settings and available data of dynamic rate symbol.

It is all written down already how to do it.


Thank you so much @fxshrat for your time and support. I just find out that I copied my post to the forum incorrectly! :frowning:
Yes, you are right. I had the same calculation for Margin deposit.

For the pairs USDCAD or USDCHF, we have:

MarginDeposite = Units × 1/leverage

For the pairs AUDUSD or EURUSD, we would have

MarginDeposite = Close × Units × 1/leverage

But I don't understand why this is not correct?
For EURCAD, we should have:

MarginDeposite = Close × Units × 1/leverage / (Close_USDCAD)

and for GBPAUD:

MarginDeposite = Close × Units × 1/leverage × (Close_AUDUSD)

Regarding the second part of my question and error of profit calculation, here are some screenshots of my settings.
Would you kindly advice what might be the error to my end.
Thanks again.


Your 3rd example is not incorrect but it can be written the same way as 2nd one I corrected yesterday.

For USD account and below pairs
it is ...
MarginDeposite = Units / leverage * pairprice.

So it is equal to 2nd example of yesterday.

pairprice is EURUSD in case of EURCAD and it is GBPUSD in case of GBPAUD.
Why? Because you buy 1 lot EUR and 1 lot GBP so to get USD margin deposit you multiply by XXXUSD.

If you look at your formula then you should see already that EURCAD/USDCAD = EURUSD

Elementary school math.

Take a look at your commissions.


4*2*100,000 = -800,000 commisions plus trade P/L. So you end up with -800,026.23.

So since you trade 1 lot (100,000 units) and commissions are per lot divide your commissions by units.
So since you have set commissions of $4 per lot per half turn enter 4/100,000 -> 4e-05 instead.


Or keep commissions at $4 and use positive margin (1000*C for Yen pairs) and 100k PointValue and 1 lot position size.

BTW, please don't post code as picture but with code tags.