NexusFi: Find Your Edge


Home Menu

 





Multi-Charts EMA strategy optimization


Discussion in MultiCharts

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




 
Search this Thread
  #1 (permalink)
Ryan26986
Whitewater, WI
 
Posts: 5 since May 2013
Thanks Given: 0
Thanks Received: 0

In multi-charts i have written a system using power language that I am looking to optimize I am having issues getting the trade to actually play out the way I want

The entry for the strategy is determined by the cross of a fast ema and a slow ema on the 1 day chart of the USD/JPY and is also limited by whether price is above the 20 day moving average when optimized I should be able to test it on the 1 hour chart with the same code and instead just use a 480 period MA

My problem is I am able to write the code for an entry order but I cannot figure out why it wont recognize the ema's crossing under represented by a condition to exit a position I am using multi charts and the regular PowerLanguage if anyone can help I can send you the code to see whats wrong


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Asia Equities Crash Overnight -- Nikkei -5.2%, KOSPI -6. …
Traders Hideout
El Clasico Draws $9.2M in Prediction Market Action -- Bi …
Prediction Markets & Event Contracts
Hungary Called for Magyar at 97pct, Ending 16-Year Orban …
Prediction Markets & Event Contracts
UMA Votes Tonight: Polymarkets $80M Strategy Bitcoin Bat …
Prediction Markets & Event Contracts
Iran Update May 8: Still Reviewing MOU, Demands Reparati …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
23 thanks
2026 Jlab journal
10 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
2026 Fire Horse
5 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,447 since Apr 2013
Thanks Given: 493
Thanks Received: 1,639

What do you have for the exit part so far? Post it here and we can take a look at it.


Follow me on X Reply With Quote
  #3 (permalink)
Ryan26986
Whitewater, WI
 
Posts: 5 since May 2013
Thanks Given: 0
Thanks Received: 0



ABCTG View Post
What do you have for the exit part so far? Post it here and we can take a look at it.


inputs:
Price (Close),
emafastlength ( 5 ),
emaslowlength ( 13 ),
stopdist ( 200 ),
NumContractsbuy ( 5 ),
NumContractssell ( 4 ),
smalength ( 480 );

vars:
smav ( 0 ),
emafv ( 0 ),
emasv ( 0 );

smav = Average ( Price, smalength );
emafv = XAverage ( Price, emafastlength );
emasv = XAverage ( Price, emaslowlength );

Condition1 = emafv crosses over emasv;
Condition2 = emafv crosses under emasv;

// Open new positions

if Condition1 and CurrentBar > smav then

Buy ("Enter xma long") (NumContractsbuy) Contracts Next Bar At open;
SetStopLoss ( Stopdist );


if Condition2 and CurrentBar < smav then

Sell ("Enter xma short") (NumContractssell) Contracts Next Bar At open;
SetStopLoss ( Stopdist );

// Open order management

if Marketposition = 1 then begin

if Condition2 then

Sell from Entry ("Enter xma long") this bar At close;


if Marketposition = -1 then begin

if condition1 then

Buy from Entry ("Enter xma short") this bar at close


Reply With Quote
  #4 (permalink)
Ryan26986
Whitewater, WI
 
Posts: 5 since May 2013
Thanks Given: 0
Thanks Received: 0


ABCTG View Post
What do you have for the exit part so far? Post it here and we can take a look at it.

I also forgot to mention that I have an optimizable number of contracts relative to the Buy and Sell orders


Reply With Quote
  #5 (permalink)
Ryan26986
Whitewater, WI
 
Posts: 5 since May 2013
Thanks Given: 0
Thanks Received: 0


ABCTG View Post
What do you have for the exit part so far? Post it here and we can take a look at it.

My error as of right now is coming in when I am in a short position trying to exit that position


Reply With Quote
  #6 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,447 since Apr 2013
Thanks Given: 493
Thanks Received: 1,639

Okay, at a quick glance I am seeing the problem that you are using the wrong reserved words for the short entry and for the exit.

The reserved words for entering and exiting positions are:

Buy - for entering a long positon
Sell - to exit a long position

SellShort - to enter a short position
BuyToCover - to exit a short position


Having said this your long entry and exit seems correct, just exchange the reserved words for the short entry and exit.

That might do it already.

Regards,
ABCTG


Follow me on X Reply With Quote
  #7 (permalink)
Ryan26986
Whitewater, WI
 
Posts: 5 since May 2013
Thanks Given: 0
Thanks Received: 0


ABCTG View Post
Okay, at a quick glance I am seeing the problem that you are using the wrong reserved words for the short entry and for the exit.

The reserved words for entering and exiting positions are:

Long - for entering a long positon
Sell - to exit a long position

SellShort - to enter a short position
BuyToCover - to exit a short position


Having said this your long entry and exit seems correct, just exchange the reserved words for the short entry and exit.

That might do it already.

Regards,
ABCTG


ABCTG

I am able to use "Buy" for entering positions but some of the other reserve words were incorrect and I think I had a misplaced End; but I was finally able to compile thanks for the help

Best,
Ryan


Reply With Quote
  #8 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,447 since Apr 2013
Thanks Given: 493
Thanks Received: 1,639


Ryan26986 View Post
ABCTG

I am able to use "Buy" for entering positions but some of the other reserve words were incorrect and I think I had a misplaced End; but I was finally able to compile thanks for the help

Best,
Ryan

Ryan, my bad it should read "Buy" for entering a long position. That's the correct reserved word for entering a long position.

One thing I also noticed, that you only need to use "SetStopLoss ( Stopdist );" once, in case you are using it with the same value. If you want to use different stops for a long and short, you'd have to place it within a
 
Code
if MarketPosition = 1 then 
begin
....
end;

if MarketPosition = -1 then 
begin
....
end;
bracket.

You can use the default stop code, to choose if the stop amount should be used for the whole position or per contract
 
Code
inputs: PositionBasis( false ); //if true, the stop amount will be used for the total position, if false it's per 
                                              //contract/share

if PositionBasis then 
	SetStopPosition
else
	SetStopShare ;
Have a nice weekend,
ABCTG


Follow me on X Reply With Quote
  #9 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,447 since Apr 2013
Thanks Given: 493
Thanks Received: 1,639

Your code might look like this:

 
Code
inputs:
Price (Close),
emafastlength ( 5 ),
emaslowlength ( 13 ),
stopdist ( 200 ),
NumContractsbuy ( 5 ),
NumContractssell ( 4 ),
smalength ( 480 ),
PositionBasis( false ); {if true, the stop amount will be used for the total position, if false it's per 
                                              contract/share}

vars:
smav ( 0 ),
emafv ( 0 ),
emasv ( 0 );

smav = Average ( Price, smalength );
emafv = XAverage ( Price, emafastlength );
emasv = XAverage ( Price, emaslowlength );

Condition1 = emafv crosses over emasv;
Condition2 = emafv crosses under emasv;

// Open new positions

if Condition1 and CurrentBar > smav then

Buy ("Enter xma long") (NumContractsbuy) Contracts Next Bar At open;



if Condition2 and CurrentBar < smav then

SellShort ("Enter xma short") (NumContractssell) Contracts Next Bar At open;

// Open order management

if Marketposition = 1 and Condition2 then
Sell from Entry ("Enter xma long") this bar At close;

if Marketposition = -1 and condition1 then
BuyToCover from Entry ("Enter xma short") this bar at close;


//stop loss
if PositionBasis then 
	SetStopPosition
else
	SetStopShare ;

SetStopLoss ( Stopdist );


Follow me on X Reply With Quote




Last Updated on May 11, 2013


© 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