Click here to Skip to main content
15,887,175 members
Home / Discussions / C#
   

C#

 
QuestionRe: modal popup inside another modal popup Pin
Eddy Vluggen30-Apr-13 0:59
professionalEddy Vluggen30-Apr-13 0:59 
AnswerRe: modal popup inside another modal popup Pin
GuyThiebaut30-Apr-13 1:45
professionalGuyThiebaut30-Apr-13 1:45 
GeneralRe: modal popup inside another modal popup Pin
Eddy Vluggen30-Apr-13 2:11
professionalEddy Vluggen30-Apr-13 2:11 
GeneralRe: modal popup inside another modal popup Pin
GuyThiebaut30-Apr-13 2:22
professionalGuyThiebaut30-Apr-13 2:22 
GeneralRe: modal popup inside another modal popup Pin
Eddy Vluggen30-Apr-13 2:52
professionalEddy Vluggen30-Apr-13 2:52 
GeneralRe: modal popup inside another modal popup Pin
GuyThiebaut30-Apr-13 2:53
professionalGuyThiebaut30-Apr-13 2:53 
QuestionVFW blank frames at start of avi Pin
Boris The Bold29-Apr-13 23:24
Boris The Bold29-Apr-13 23:24 
QuestionBuying stock is easy, selling it is worse... loop problems? Pin
lordoftrades29-Apr-13 22:33
lordoftrades29-Apr-13 22:33 
Hello

I'm trying to create a program that scan the values and compare values against some average highest or loweste values. It seems to me that the entry is no problem, but getting out of the position is not working as it should.

I'm used to VBA, and there I'd just set up a loop to start IF an entrysignal was trigged. And that loop would run until exitsignal was trigged...

But I'm not experienced at all with writing in C#, so I'm not sure how this code actually runs, ie step-by-step:

C#
// Check whether the indicator value is oversold.
            if (Value < yesterdayslowest50Value && yyesterdayslowest50Value > yesterdaysValue) {
                // Check whether a short position exists for the symbol.
                if (_enableShorting && PositionExists(IQ_TradeStatus.OPEN, symbolIndex, IQ_Direction.SHORT_SIDE)) {
                    // Generate a buy to cover market order.
                    BrokerMarket(IQ_ActionType.BUY_TO_COVER, symbolIndex, 0, IQ_TIF.DAY, "CoverToLong");
                }
                // Check whether there are no long positions for the symbol.
                if (!PositionExists(IQ_TradeStatus.OPEN, symbolIndex, IQ_Direction.LONG_SIDE)) {
                    // Generate a buy market order.
                    int orderIndex = BrokerMarket(IQ_ActionType.BUY, symbolIndex, 0, IQ_TIF.DAY, "Long");
                    // Set a stop loss on the order.
                    BrokerSetStopLossPercent(orderIndex, _stopLoss, true, "");
                    // Set a take profit on the order.
                    BrokerSetTakeProfitPercent(orderIndex, _takeProfit, true, "");
                    // Set a trailing stop loss on the order.
                    BrokerSetTrailingStopLoss(orderIndex, _isPercent, _trailingStop, "");
                }
                //When to exit:
                if(Value > yesterdayshighest13Value && yesterdaysValue < yyesterdayshighest13Value && PositionExists(IQ_TradeStatus.OPEN, symbolIndex))
                    {
                        int[] positionIndexes = PositionIndexList(IQ_TradeStatus.OPEN, symbolIndex);
                        double quantity = PositionQuantity(positionIndexes[0]);
                        BrokerMarket(IQ_ActionType.SELL, symbolIndex, quantity, IQ_TIF.DAY, "Sell");
                    }
            }
            // Check whether the indicator value is overbought.
            else if (Value > yesterdayslowest13Value && yyesterdayslowest13Value < yesterdaysValue) {
                // Check whether a long position exists.
                if (PositionExists(IQ_TradeStatus.OPEN, symbolIndex, IQ_Direction.LONG_SIDE)) {
                    // Generate a sell market order.
                    BrokerMarket(IQ_ActionType.SELL, symbolIndex, 0, IQ_TIF.DAY, "SellToShort");
                }
                // Check whether a short position doesn't exist.
                if (_enableShorting && !PositionExists(IQ_TradeStatus.OPEN, symbolIndex, IQ_Direction.SHORT_SIDE)) {
                    // Generate a sell short market order.
                    int orderIndex = BrokerMarket(IQ_ActionType.SELL_SHORT, symbolIndex, 0, IQ_TIF.DAY, "Short");
                    // Set a stop loss on the order.
                    BrokerSetStopLossPercent(orderIndex, _stopLoss, true, "");
                    // Set a take profit on the order.
                    BrokerSetTakeProfitPercent(orderIndex, _takeProfit, true, "");
                    // Set a trailing stop loss on the order.
                    BrokerSetTrailingStopLoss(orderIndex, _isPercent, _trailingStop, "");
                }
                //When to exit:
                if(Value < yesterdayslowest13Value && yesterdaysValue > yyesterdayslowest13Value && PositionExists(IQ_TradeStatus.OPEN, symbolIndex))
                    {
                        int[] positionIndexes = PositionIndexList(IQ_TradeStatus.OPEN, symbolIndex);
                        double quantity = PositionQuantity(positionIndexes[0]);
                        BrokerMarket(IQ_ActionType.BUY_TO_COVER, symbolIndex, quantity, IQ_TIF.DAY, "Cover");
                    }
            }


It seems that my code have issues exiting the trades. BTW I've used IQBrokers software to program this.

If anyone see some obviouse mistake I'd appreciate it.
Kind regards
Espen

AnswerRe: Buying stock is easy, selling it is worse... loop problems? Pin
Eddy Vluggen29-Apr-13 23:04
professionalEddy Vluggen29-Apr-13 23:04 
GeneralRe: Buying stock is easy, selling it is worse... loop problems? Pin
lordoftrades29-Apr-13 23:07
lordoftrades29-Apr-13 23:07 
GeneralRe: Buying stock is easy, selling it is worse... loop problems? Pin
Richard MacCutchan29-Apr-13 23:23
mveRichard MacCutchan29-Apr-13 23:23 
GeneralRe: Buying stock is easy, selling it is worse... loop problems? Pin
Eddy Vluggen29-Apr-13 23:32
professionalEddy Vluggen29-Apr-13 23:32 
AnswerRe: Buying stock is easy, selling it is worse... loop problems? Pin
Freak3029-Apr-13 23:40
Freak3029-Apr-13 23:40 
AnswerRe: Buying stock is easy, selling it is worse... loop problems? Pin
dusty_dex30-Apr-13 1:00
dusty_dex30-Apr-13 1:00 
GeneralRe: Buying stock is easy, selling it is worse... loop problems? Pin
lordoftrades30-Apr-13 1:05
lordoftrades30-Apr-13 1:05 
QuestionSessionUnlock event not firing sometimes in C# window service Pin
Abhishek Shankhdhar29-Apr-13 22:08
Abhishek Shankhdhar29-Apr-13 22:08 
AnswerRe: SessionUnlock event not firing sometimes in C# window service Pin
Pete O'Hanlon29-Apr-13 22:22
mvePete O'Hanlon29-Apr-13 22:22 
GeneralRe: SessionUnlock event not firing sometimes in C# window service Pin
Abhishek Shankhdhar29-Apr-13 22:30
Abhishek Shankhdhar29-Apr-13 22:30 
GeneralRe: SessionUnlock event not firing sometimes in C# window service Pin
Eddy Vluggen29-Apr-13 23:06
professionalEddy Vluggen29-Apr-13 23:06 
Questiondatabase schema Pin
gashkori29-Apr-13 6:23
gashkori29-Apr-13 6:23 
AnswerRe: database schema Pin
Dave Kreskowiak29-Apr-13 7:05
mveDave Kreskowiak29-Apr-13 7:05 
AnswerRe: database schema Pin
Mycroft Holmes29-Apr-13 14:26
professionalMycroft Holmes29-Apr-13 14:26 
GeneralRe: database schema Pin
gashkori29-Apr-13 21:24
gashkori29-Apr-13 21:24 
Questiontext steganography Pin
Member 1000977129-Apr-13 1:52
Member 1000977129-Apr-13 1:52 
AnswerRe: text steganography Pin
Eddy Vluggen29-Apr-13 2:15
professionalEddy Vluggen29-Apr-13 2:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.