Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Beginner Advice Needed

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • pswarts
    replied
    thanks koganam
    I'll swap them around ,but what do you mean with no branching.I embedded the If conditions or thought I did. Did I do it wrong,should I be using Else if or am I not understanding what exactly you mean with branching

    Leave a comment:


  • koganam
    replied
    There is a logic problem: not in the code, but in the process. Your conditions are in the order from most restrictive to least restrictive. with no branching. Hence all blocks of the code will be executed. Naturally, that means that the least restrictive code will always be the last executed, and will, therefore, be the gate on your processing.

    Leave a comment:


  • pswarts
    replied
    Continued

    // StopLoss/(Profit) Condition 3
    if (Position.MarketPosition != MarketPosition.Flat
    && Close[
    0] >= Position.AvgPrice + ((2 * Profitfactor) * (ATR(20)[0]))
    && Low[
    0] >= Low[1])
    {
    ExitLongStop(Low[
    3],"P3");

    // StopLoss Condition 2
    if (Position.MarketPosition != MarketPosition.Flat
    && Close[
    0] >= Position.AvgPrice + ((1 * Profitfactor) * (ATR(20)[0])))
    {
    ExitLongStop(Position.AvgPrice,
    "P2");
    ExitLongStop(Position.AvgPrice,
    "P3");

    // StopLoss Condition 1
    if (Position.MarketPosition != MarketPosition.Flat)
    {
    ExitLongStop(Position.AvgPrice - ((
    2 * Profitfactor) * (ATR(20)[0])),"P1");
    ExitLongStop(Position.AvgPrice - ((
    2 * Profitfactor) * (ATR(20)[0])),"P2");
    ExitLongStop(Position.AvgPrice - ((
    2 * Profitfactor) * (ATR(20)[0])),"P3");
    }
    }
    }
    }

    Leave a comment:


  • pswarts
    replied
    Profit conditions

    Problem is the targets/stops does not execute correctly when backtesting: code as follows


    protected
    overridevoid OnBarUpdate()
    if(My Entry Conditions)
    {
    EnterLongStop(
    1, High[0], "P1");
    EnterLongStop(
    1, High[0], "P2");
    EnterLongStop(
    1, High[0], "P3");
    }
    // Profit Conditions
    if (Position.MarketPosition != MarketPosition.Flat)
    {
    SetProfitTarget(
    "P1",CalculationMode.Price, Position.AvgPrice + ((1 * Profitfactor) * (ATR(20)[0])));
    SetProfitTarget(
    "P2",CalculationMode.Price, Position.AvgPrice + ((2 * Profitfactor) * (ATR(20)[0])));
    }

    Leave a comment:


  • pswarts
    replied
    Hi
    Like most newbies I back.
    Coded my Masterpiece ...lol... unfortunately as expected it's not working. Can I please post my code here so someone can have a look at it and give some pointers?

    Leave a comment:


  • NinjaTrader_RyanM1
    replied
    Hello pswarts,

    Thanks for the post and welcome to the NinjaTrader forums.

    If you want to scale out of your strategy you must first scale into it, so 3 separate unique entries. A basic scale out strategy is available here:


    When you are just getting started, SetProfitTarget() and SetStopLoss() are more convenient and recommended. They are automatically submitted upon entry execution, and with mode ticks or percent, they're automatically placed in relation to your entry price.

    Once you get more experience and can use the advanced order handling, ExitLongStop() and ExitLongLimit() will offer more control and flexibility.

    Leave a comment:


  • pswarts
    started a topic Beginner Advice Needed

    Beginner Advice Needed

    New to this. Learning by starting w/ Wizard then Unlock code and copy/paste bits of code found in forum. Working well so far. I plan to start coding my strategy and have few question before I start wrong and have to redo all:

    I have a strategy that Enters with 3positions:
    I will have StopLoss (and Profits) initially at (x)*ATR, but then my Stops will trail at low/high of (x) bars till after 1st Target, then move to Breakeven till 2nd Target, then trail by Low/High Bars again till 3rd is stopped out.
    Q: Is it better to Enter 1 position and set stops and profits to 1/3 the amount or is it better to do 3 Unique Entries and link Stops/Profits to those.
    Also is it better to use SetStopLoss() and SetProfitTarget() or would ExitLong/Short() be more flexible

    Got most of the rest of what I need already from the Forum. Great work!!!

    Thanks

    Just realized this is in the wrong category.Sorry. Dont know how to move it
    Last edited by pswarts; 11-22-2011, 05:26 PM.

Latest Posts

Collapse

Topics Statistics Last Post
Started by SalmaTrader, 07-07-2026, 10:26 PM
0 responses
103 views
0 likes
Last Post SalmaTrader  
Started by CarlTrading, 07-05-2026, 01:16 PM
0 responses
62 views
0 likes
Last Post CarlTrading  
Started by CaptainJack, 06-17-2026, 10:32 AM
0 responses
28 views
0 likes
Last Post CaptainJack  
Started by kinfxhk, 06-17-2026, 04:15 AM
0 responses
36 views
0 likes
Last Post kinfxhk
by kinfxhk
 
Started by kinfxhk, 06-17-2026, 04:06 AM
0 responses
40 views
0 likes
Last Post kinfxhk
by kinfxhk
 
Working...
X