NexusFi: Find Your Edge


Home Menu

 





Creating a new function in Amibroker


Discussion in Platforms and Indicators

Updated
    1. trending_up 2,523 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 1 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
milkysahai001
Agra+India
 
Posts: 42 since Sep 2016
Thanks Given: 17
Thanks Received: 3

i need to create a function MarketPosition in Amibroker, just like the one in MultiCharts. description in MultiCharts:
MarketPosition(N) returns whether the strategy is currently flat, short, or long on the current bar or for
N closed positions ago. MarketPosition return values are:
-1 for a short position.
1 for a long position.
0 for flat (no position).

I want to create same kind of function in Amibroker, but not good enough at coding.
Can somebody please help me do this.


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Day 96 Missiles Hit Kuwait and Bahrain: June 15 Peace at …
Prediction Markets & Event Contracts
Kalshi Sets $4.13B All-Time Weekly Record as Polymarket …
Prediction Markets & Event Contracts
Victory Day Delivers: Russia-Ukraine Ceasefire Market Cl …
Prediction Markets & Event Contracts
The Confluence Meter: A Multi-Layered Signal Framework B …
The Elite Circle
Orban Crashes to 21pct on Record Turnout -- McIlroy Drop …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #2 (permalink)
alligator
paris france
 
Posts: 10 since Sep 2013
Thanks Given: 10
Thanks Received: 5

This thread is old, but it's a classic so I answer it as it could be useful for other people.

Use the Flip() function. In the following I assume you have defined your system using variables Buy/Sell/Short/Cover.
If one of them is not defined, assign 0 to it e.g if you have no short position:
 
Code
Short = Cover = 0; // no short positions

Now here's the solution to your problem:
 
Code
MarketPosition = Flip(Buy, Sell) - Flip(Short, Cover);

Yes, it's a one-liner, that's the magic of AFL.


Reply With Quote
Thanked by:




Last Updated on October 9, 2017


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts