NexusFi: Find Your Edge


Home Menu

 





Translate For Loop in Easy Language to NT C#


Discussion in NinjaTrader

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




 
Search this Thread

Translate For Loop in Easy Language to NT C#

  #1 (permalink)
 
Crassius's Avatar
 Crassius 
Shenandoah Valley, VA
 
Experience: Advanced
Platform: NT8
Broker: NinjaTrader introduced to Dorman
Trading: ES, CL, 6E, ZN
Posts: 14 since Jan 2011
Thanks Given: 5
Thanks Received: 3

I'm working on some John Ehler's Easy Language code, and I have reached this section that is so far over my head I'll never be able to translate it.

{Sum DeltaPhases to reach 360 degrees. The sum is the instantaneous period.}

InstPeriod = 0;
Value4 = 0;

For count = 0 to 50 begin
Value4 = Value4 + DeltaPhase[count];
If Value4 > 360 and InstPeriod = 0 then begin
InstPeriod = count;
end;
end;

Will you please translate that into C#?

Follow me on Twitter Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
Exit Strategy
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
18 thanks
GFIs1 1 DAX trade per day journal
16 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
13 thanks
  #3 (permalink)
 
sunpost's Avatar
 sunpost 
Pennsylvania, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB/Kinetick
Trading: Forex
Posts: 60 since Aug 2010
Thanks Given: 202
Thanks Received: 42


give this a try...
 
Code
 
int InstPeriod = 0;
int Value4 = 0;
for (int count = 0; count <= 50; count++)
{
     Value4 =+ DeltaPhase[count];
     if (Value4 > 360 && InstPeriod == 0)
     {
          InstPeriod = count;
     }
}

Reply With Quote
Thanked by:
  #4 (permalink)
 
Crassius's Avatar
 Crassius 
Shenandoah Valley, VA
 
Experience: Advanced
Platform: NT8
Broker: NinjaTrader introduced to Dorman
Trading: ES, CL, 6E, ZN
Posts: 14 since Jan 2011
Thanks Given: 5
Thanks Received: 3

Thanks for taking a stab at it Sunpost... who wrote..

int InstPeriod = 0;
int Value4 = 0;
for (int count = 0; count <= 50; count++)
{
Value4 =+ DeltaPhase[count];
if (Value4 > 360 && InstPeriod == 0)
{
InstPeriod = count;
}
}


DeltaPhase is just a double, so I dropped the [count] from DeltaPhase[count] in your answeras that would not compile... looks like the compiler was thinking the [count] was addressing an array... so I have this now...

//Sum DeltaPhases to reach 360 degrees. The sum is the instantaneous period.
InstPeriod = 0;
Value4 = 0;

for (int count = 0; count < 50; count++)
{
Value4 =+ DeltaPhase;
DrawTextFixed("Tag1",Value4.ToString(),TextPosition.BottomRight); //for debugging
if (Value4 >360 && InstPeriod == 0)
{
InstPeriod = count;
DsInstPeriod[0] = InstPeriod;
//DrawTextFixed("Tag1",InstPeriod.ToString(),TextPosition.BottomRight);
}
}


The DrawTexts I'm using for debugging... What's happening is that DeltaPhase gets added to Value4 once, and gets drawn, but then the if statement never executes... I believe because the loop doesn't run, doesn't keep adding DeltaPhase to Value4, so Value 4 never gets greater than 360 for the if statement to evaluate to true.

Any help much appreciated.

Follow me on Twitter Started this thread Reply With Quote
  #5 (permalink)
 
sunpost's Avatar
 sunpost 
Pennsylvania, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB/Kinetick
Trading: Forex
Posts: 60 since Aug 2010
Thanks Given: 202
Thanks Received: 42

The issue with the statements in the if not being reached after the first time is that InstPeriod gets set to a value other than 0 making the condition (InstPeriod == 0) false.

 
Code
 
if (Value4 >360 &&InstPeriod == 0)
{
    InstPeriod = count;
     DsInstPeriod[0] = InstPeriod;
     //DrawTextFixed("Tag1",InstPeriod.ToString(),TextPos ition.BottomRight);
}

Reply With Quote
  #6 (permalink)
 
Crassius's Avatar
 Crassius 
Shenandoah Valley, VA
 
Experience: Advanced
Platform: NT8
Broker: NinjaTrader introduced to Dorman
Trading: ES, CL, 6E, ZN
Posts: 14 since Jan 2011
Thanks Given: 5
Thanks Received: 3

Thanks for the help sunpost...

I got the loop running.... indicator doesn't look right, but at least its plotting something other than 0. I probably have something wrong up in the ArcTangent math to debug...


what was wrong with the loop was I had

Value4 =+ DeltaPhase;

instead of +=

Progress has been made.... however. Thanks.

Follow me on Twitter Started this thread Reply With Quote
  #7 (permalink)
 
sunpost's Avatar
 sunpost 
Pennsylvania, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB/Kinetick
Trading: Forex
Posts: 60 since Aug 2010
Thanks Given: 202
Thanks Received: 42

great progress @Crassius!

You might be interested in a webinar today by @shodson...
Introduction to C# and NinjaScript Programming
Trading Webinar's - [AUTOLINK]Big Mike Trading[/AUTOLINK] Forum

Reply With Quote
Thanked by:




Last Updated on February 23, 2011


© 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