NexusFi: Find Your Edge


Home Menu

 





Is this possible to do?


Discussion in MultiCharts

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




 
Search this Thread

Is this possible to do?

  #11 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

Gibban,

you need to either store the stop price when you compute the buy limit price and make sure it doesn't get updated any more while you are in a position. Something like this should work for you.
 
Code
//not long
if MarketPosition < 1 then
begin
         BuyLimitPrice = ...
         LongStopPrice = ...
end;
These values can update while you are either short of flat and as soon as you are long the values can't change anymore.

Regards,
ABCTG

Follow me on Twitter Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Cheap historycal L1 data for stocks
Stocks and ETFs
MC PL editor upgrade
MultiCharts
 
  #12 (permalink)
 Gibban 
Stockholm
 
Experience: Beginner
Platform: NinjaTrader, MultiCharts
Trading: Forex
Posts: 14 since Feb 2014
Thanks Given: 25
Thanks Received: 4

Hello ABCTG!

I don't know if I understand you right, there is something that I am missing in the code!
Probably a lot, but this is my first lines of cod.

Regards
//G

 
Code
Input: {-------------------------------------------------------------------------------------}

RSIThreshold(10),
RSILookback(2),
ATRThreshold(10),
ATRBuyLimit(0.1),
ATRProfitTarget(1),
ATRStoploss(3),
DayExitPeriod(5);

Variables: {---------------------------------------------------------------------------------}
RSI_Value(0),
MA200(0),
ATR(0),
BuyLimitPrice(0),
StopLossPrice(0),
MP(0);

{=== START OF MAIN PROGRAM ==================================================================} 

RSI_Value = RSI(Close,RSILookback);
MA200 =  Average(Close, 200);
ATR =  AverageTrueRange(AtrThreshold);
MP = MarketPosition;
BuyLimitPrice = Close [1] - ATRBuyLimit [1] * ATR [1];
StopLossPrice = BuyLimitPrice - ATRStoploss [1]* ATR [1];

//SetupDay +1 = EntryDay
If ( RSI_Value <= RSIThreshold ) And ( Close > MA200 ) Then 
	Buy ("Long") next bar at (Close [1] - ATRBuyLimit * ATR ) limit;
	
//Target (OK)
If MP = 1 Then Sell ("LTarget") Next bar at (EntryPrice + (ATRProfitTarget * ATR)) Limit;
	
//ExitDays (OK)
If ( Barssinceentry = DayExitPeriod ) Then sell ("DayExitPeriod") this bar at close;

//Not Long
If MP < 1 then
begin
         BuyLimitPrice =  - ATRBuyLimit * ATR ;
         StopLossPrice =  BuyLimitPrice - ATRStoploss * ATR ;
end;

//StopLoss
If MP = 1 Then Sell ("SLoss") this bar at StopLossPrice limit;

Started this thread Reply With Quote
  #13 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629


Gibban,

what does your code do, that you think you are missing something?
One thing I noticed is that your stop order is a limit order. As limit orders are executed at this price or better, a limit order to sell below the current market price will be filled right away.

Regards,
ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #14 (permalink)
 Gibban 
Stockholm
 
Experience: Beginner
Platform: NinjaTrader, MultiCharts
Trading: Forex
Posts: 14 since Feb 2014
Thanks Given: 25
Thanks Received: 4

ABCTG,

I don't know witch options I have for the StopLoss function!

 
Code
//StopLoss
If MP = 1 Then Sell ("SLoss") this bar at StopLossPrice limit;
As you see the code now it do not compile!

/g

Started this thread Reply With Quote
  #15 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

Gibban,

when starting out with learning EasyLanguage or PowerLanguage (or any other language for that matter) I would suggest not to jump into something complex like strategy development right away. Start with the basics and move forward step by step.

Regarding your code, the compiler points you to the issues and gives an idea about the solution in the Output tab. I don't have a function called AverageTrueRange within my PL Editor. This is the first error I am running into, so for the code to compile on my end this needs to be changed to the default AvgTrueRange function.
The next thing is that your limit order for the stop can't be used with the phrase "this bar" - the error message "'This bar' can only be used in close orders.", points you toward this. So you need to change it to "next bar" and for the order to be a stop order use "stop" instead of "limit". Change this and the code will compile fine.

Regards,
ABCTG

Follow me on Twitter Reply With Quote
  #16 (permalink)
 Gibban 
Stockholm
 
Experience: Beginner
Platform: NinjaTrader, MultiCharts
Trading: Forex
Posts: 14 since Feb 2014
Thanks Given: 25
Thanks Received: 4

Thank you ABCTG!

Yes you are right, I should not dig in to this!
But as I say this is my first signal and I did not realize how hard it was!!

I thought it was only couple of lines for this simple strategy, but I was wrong there.
Maybe I should give the code to a professional EL programmer, but then I had not learned anything.

At the moment the strategy is working with the StopLoss function, just a minor adjustments on the entry price. It is little bit to high.

Again thank you so much for your help!

Regards
Gibban

Started this thread Reply With Quote
Thanked by:
  #17 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

You are welcome. I have learned a lot from other coders when I started out, so a proper commented and written code by someone else can still help you making a lot of progress in your learning.
Forums are also a great source when you can get help with coding problems.

Regards,
ABCTG


Gibban View Post
I thought it was only couple of lines for this simple strategy, but I was wrong there.
Maybe I should give the code to a professional EL programmer, but then I had not learned anything.


Follow me on Twitter Reply With Quote
Thanked by:




Last Updated on May 30, 2014


© 2024 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 - Privacy Policy - Downloads - Top
no new posts