NexusFi: Find Your Edge


Home Menu

 





PrintWithTimeStamp problems...


Discussion in NinjaTrader

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




 
Search this Thread
  #1 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 801

Looking for some help if I may. I want my code to PrintWithTimeStamp when an Entry signal is generated. The following code prints both the Long and Short signals at the same time, and seems to ignore all the code above it such as if (Position.MarketPosition != MarketPosition.Flat) return;.

Here you go:

 
Code
                            
protected override void OnBarUpdate()
{
EntryHandling EntryHandling.UniqueEntries;
 
if (
Bars.FirstBarOfSession)
{
// AllTrades includes virtual and real-time trades. For real-time trades please use .RealtimeTrades
priorTradesCumProfit Performance.AllTrades.TradesPerformance.Currency.CumProfit;
}
 
if (
UseSessionPnL == true && (Performance.AllTrades.TradesPerformance.Currency.CumProfit priorTradesCumProfit >= sessionProfitTarget
|| Performance.AllTrades.TradesPerformance.Currency.CumProfit priorTradesCumProfit <= (-1*sessionLossLimit))) return;
 
if (
Position.MarketPosition != MarketPosition.Flat) return;
 
if (
UseTradeTime==true && ToTime(Time[0]) <= tradeStartTime || ToTime(Time[0]) >= tradeEndTime) return; 
 
if (
GetRandom() == (int) RandomLimit 2)
{
if (
GetRandom2() % == 0)
GoLong();
if (!
Historical)

PrintWithTimeStamp(Instrument.FullName " STRATEGY Erratic NT7: LONG signal generated with ASK at: " GetCurrentAsk()); //For basic TCA
}
else
GoShort();
if (!
Historical)

PrintWithTimeStamp(Instrument.FullName " STRATEGY Erratic NT7:SHORT signal generated with BID at: " GetCurrentBid()); //For basic TCA
}
}
 

Any thoughts on what I'm doing wrong? Thanks!


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
SEC Chairman Calls for New Golden Age of SEC-CFTC Regula …
Traders Hideout
More Than Capable: Hegseths War Warning Validates $114M …
Prediction Markets & Event Contracts
Day 96 Missiles Hit Kuwait and Bahrain: June 15 Peace at …
Prediction Markets & Event Contracts
Iran War Prediction Markets: Ceasefire 16%, Ground Invas …
Prediction Markets & Event Contracts
Iran Ceasefire Surges to 19.5% on US 15-Point Plan -- 82 …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
21 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
  #3 (permalink)
 
gregid's Avatar
 gregid 
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 649 since Aug 2009
Thanks Given: 320
Thanks Received: 623


I am not sure what is the exact logic you need but I would definitely take a closer look at your brackets - indentation may prove useful.

Anyway here is my try:
 
Code
                            
if (GetRandom() == (int) RandomLimit 2)
{
    if (
GetRandom2() % == 0)
    {
        
GoLong();
        if (!
Historical)
        { 
            
PrintWithTimeStamp(Instrument.FullName " STRATEGY Erratic NT7: LONG signal generated with ASK at: " GetCurrentAsk()); //For basic TCA
        
}
    }
    else
    {
        
GoShort();
        if (!
Historical)
        { 
            
PrintWithTimeStamp(Instrument.FullName " STRATEGY Erratic NT7:SHORT signal generated with BID at: " GetCurrentBid()); //For basic TCA
        
}
    }


Reply With Quote
Thanked by:
  #4 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 801

gregid that worked. Thank you! Code is something from the Elite section I'm trying to improve on.


Started this thread Reply With Quote




Last Updated on February 13, 2010


© 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